Nested JSON Object with array in PHP -


i want json object follows in personal, address , itm have sequence of json object.

{   "id": "1",   "state": "12",   "personal": [               {       "name": "abc",       "contact":"1111111"       "address": [              {           "line1": "abc",           "city": "abc",           "itm": [               {               "num": 1,               "itm_detatils": {                 "itemname": "bag",                 "rate": 1000,                 "discount": 0,                }             }           ],           "status": "y"         }       ]     }   ]  } 

but getting result follows in want json array @ address , itm_details.

{   "id": "1",   "state": "12",   "personal": [     {       "name": "abc",       "contact": "1111111",       "address": {         "line1": "abc",         "city": "abc",         "itm": {           "inum": "1",           "itm_detatils": {             "itemname": "bag",             "rate": 1000,             "discount": 0           }         },         "status": "y"       }     }   ] } 

my php code follow: in creating simple array , after array inside array during encoding json it's not showing sequence of json object.

$a=array(); $a["id"]="1"; $a["state"]="12"; $a["personal"]=array(); $a["personal"][]=array( "name"=>"abc", "contact"=>"1111111", "address"=>array( "line1"=>"abc", "city"=>"abc", "itm"=>array(     "inum"=>"1",     "itm_detatils"=>array(         "itemname"=>"bag",         "rate"=>1000,         "discount"=>0,         ),      ), "status"=>"y",     ),     );  echo json_encode($a); 

thanks in advance.

add 1 more array

//... "address" => array(     array(         "line1"=>"abc",         "city"=>"abc",         // ...     ), ) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -