alessandro
18 Aug 2009, 5:26 AM
Hi all.
I'm having trouble generating a JSON array from PHP.
I need a tree like this:
level1
level2
level3
level3
level3
level2
Hi have the following JSON code made from PHP:
[{"text":"DNS","leaf":"false","children":[{"text":"Forwarding zone","leaf":"false","children":[[{"text":"testdomain.com","leaf":"true","id":"domain_fwd_2","children":""},{"text":"mytest.it","leaf":"true","id":"domain_fwd_1","children":""}]]},{"text":"Reverse zone","leaf":"false","children":[[{"text":"testdomain.com","leaf":"true","id":"domain_rev_2","children":""},{"text":"anothertest.org","leaf":"true","id":"domain_rev_1","children":""}]]}]}]
That code doesn't work.
I'm generating it with "json_encode" with php 5.2.
This is the original PHP array:
Array
(
[text] => DNS
[leaf] => false
[children] => Array
(
[0] => Array
(
[text] => Forwarding zone
[leaf] => false
[children] => Array
(
[0] => Array
(
[0] => Array
(
[text] => testdomain.com
[leaf] => true
[id] => domain_fwd_2
[children] =>
)
[1] => Array
(
[text] => mytest.it
[leaf] => true
[id] => domain_fwd_1
[children] =>
)
)
)
)
[1] => Array
(
[text] => Reverse zone
[leaf] => false
[children] => Array
(
[0] => Array
(
[0] => Array
(
[text] => testdomain.com
[leaf] => true
[id] => domain_rev_2
[children] =>
)
[1] => Array
(
[text] => anothertest.org
[leaf] => true
[id] => domain_rev_1
[children] =>
)
)
)
)
)
)
If you would like to try, this is the serialized array
a:3:{s:4:"text";s:3:"DNS";s:4:"leaf";s:5:"false";s:8:"children";a:2:{i:0;a:3:{s:4:"text";s:18:"Forwarding zone";s:4:"leaf";s:5:"false";s:8:"children";a:1:{i:0;a:2:{i:0;a:4:{s:4:"text";s:19:"testdomain.com";s:4:"leaf";s:4:"true";s:2:"id";s:12:"domain_fwd_2";s:8:"children";s:0:"";}i:1;a:4:{s:4:"text";s:12:"mytest.it";s:4:"leaf";s:4:"true";s:2:"id";s:12:"domain_fwd_1";s:8:"children";s:0:"";}}}}i:1;a:3:{s:4:"text";s:15:"Reverse zone";s:4:"leaf";s:5:"false";s:8:"children";a:1:{i:0;a:2:{i:0;a:4:{s:4:"text";s:19:"testdomain.com";s:4:"leaf";s:4:"true";s:2:"id";s:12:"domain_rev_2";s:8:"children";s:0:"";}i:1;a:4:{s:4:"text";s:12:"anothertest.org";s:4:"leaf";s:4:"true";s:2:"id";s:12:"domain_rev_1";s:8:"children";s:0:"";}}}}}}
I'm having trouble generating a JSON array from PHP.
I need a tree like this:
level1
level2
level3
level3
level3
level2
Hi have the following JSON code made from PHP:
[{"text":"DNS","leaf":"false","children":[{"text":"Forwarding zone","leaf":"false","children":[[{"text":"testdomain.com","leaf":"true","id":"domain_fwd_2","children":""},{"text":"mytest.it","leaf":"true","id":"domain_fwd_1","children":""}]]},{"text":"Reverse zone","leaf":"false","children":[[{"text":"testdomain.com","leaf":"true","id":"domain_rev_2","children":""},{"text":"anothertest.org","leaf":"true","id":"domain_rev_1","children":""}]]}]}]
That code doesn't work.
I'm generating it with "json_encode" with php 5.2.
This is the original PHP array:
Array
(
[text] => DNS
[leaf] => false
[children] => Array
(
[0] => Array
(
[text] => Forwarding zone
[leaf] => false
[children] => Array
(
[0] => Array
(
[0] => Array
(
[text] => testdomain.com
[leaf] => true
[id] => domain_fwd_2
[children] =>
)
[1] => Array
(
[text] => mytest.it
[leaf] => true
[id] => domain_fwd_1
[children] =>
)
)
)
)
[1] => Array
(
[text] => Reverse zone
[leaf] => false
[children] => Array
(
[0] => Array
(
[0] => Array
(
[text] => testdomain.com
[leaf] => true
[id] => domain_rev_2
[children] =>
)
[1] => Array
(
[text] => anothertest.org
[leaf] => true
[id] => domain_rev_1
[children] =>
)
)
)
)
)
)
If you would like to try, this is the serialized array
a:3:{s:4:"text";s:3:"DNS";s:4:"leaf";s:5:"false";s:8:"children";a:2:{i:0;a:3:{s:4:"text";s:18:"Forwarding zone";s:4:"leaf";s:5:"false";s:8:"children";a:1:{i:0;a:2:{i:0;a:4:{s:4:"text";s:19:"testdomain.com";s:4:"leaf";s:4:"true";s:2:"id";s:12:"domain_fwd_2";s:8:"children";s:0:"";}i:1;a:4:{s:4:"text";s:12:"mytest.it";s:4:"leaf";s:4:"true";s:2:"id";s:12:"domain_fwd_1";s:8:"children";s:0:"";}}}}i:1;a:3:{s:4:"text";s:15:"Reverse zone";s:4:"leaf";s:5:"false";s:8:"children";a:1:{i:0;a:2:{i:0;a:4:{s:4:"text";s:19:"testdomain.com";s:4:"leaf";s:4:"true";s:2:"id";s:12:"domain_rev_2";s:8:"children";s:0:"";}i:1;a:4:{s:4:"text";s:12:"anothertest.org";s:4:"leaf";s:4:"true";s:2:"id";s:12:"domain_rev_1";s:8:"children";s:0:"";}}}}}}