1

I have serialized string for jquery:

[{"id":1},
 {"id":2,"children":[{"id":3}]},
 {"id":4,"children":[{"id":5,"children":[{"id":6,"children":[{"id":7}]}]}]},
 {"id":8},{"id":9},{"id":10}
]

I want to pharse this in PHP to get something like:

 $menu = array(
 array( 'name' => 'Item 1', 'id' => '1' ,'children' => '0'), 
 array( 'name' => 'Item 2', 'id' => '2' ,'children' => '0'), 
 array( 'name' => 'Item 3', 'id' => '3' ,'children' => '2'), 
 array( 'name' => 'Item 4', 'id' => '4' ,'children' => '0'), 
 array( 'name' => 'Item 5', 'id' => '5' ,'children' => '4'), 
 array( 'name' => 'Item 6', 'id' => '6' ,'children' => '5'), 
 array( 'name' => 'Item 7', 'id' => '7' ,'children' => '6'), 
 array( 'name' => 'Item 8', 'id' => '8' ,'children' => '0'), 
 array( 'name' => 'Item 9', 'id' => '9' ,'children' => '0'), 
 array( 'name' => 'Item 10', 'id' => '10','children' => '0'), 
 );

(When children == 0, then this item is root category.)

Many thanks for sugestions. Karlis.

asked Oct 6, 2013 at 21:36

1 Answer 1

2

Check out PHP's json_decode function, documentation here.

answered Oct 6, 2013 at 21:58
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Joseph for answer. About json_decode i know, but in my jquery string is childrens and there need ( i think some recursive functioin? )

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.