javascript - Three dimensional associative array for Json? -


after several attempts, have ask solve this. below have plain json:

{     "test": {         "r1": [{             "id": 1,             "status": true         }, {             "id": 2,             "status": true         }],         "r2": [{             "id": 1,             "status": false         }, {             "id": 2,             "status": false         }]     } } 

this works fine javascript when i'm reading simple .txt file, want create json php. can make 2 dimensional associative array, seems need 3 dimensional associative array, , can't solve that! give me hint how or alternative solutions?

here's embracing example data on how convert json object (string) php array , vice-versa.
hope makes things clear you.

<?php  // original json object string $jsonstring = '{     "test":{         "r1":[{             "id":1,             "status":true         },{             "id":2,             "status":true         }],         "r2":[{             "id":1,             "status":false         },{             "id":2,             "status":false         }]     } }';  // convert json string php array // can used php script work on $phparray = json_decode($jsonstring); echo '<h3>php array converted json string</h3><pre>'; var_dump($phparray); echo '</pre>';  // convert json string prove it's same $jsonstring1 = json_encode($phparray);  // create php array corresponding original json string, manually $phparray = array (     "test"=> array (         "r1" => array(             array(                 "id"=>1,                 "status"=>true             ),             array(                 "id"=>2,                 "status"=>true             )         ),         "r2" => array(             array(                 "id"=>1,                 "status"=>false             ),             array(                 "id"=>2,                 "status"=>false             )         )     ) );  // convert php array json string // can sent browser can used javascript $jsonstring2 = json_encode($phparray);  echo '<h3>original json string</h3>' . $jsonstring; echo '<h3>after conversion array , back</h3>' . $jsonstring1; echo '<h3>converted php array</h3>' . $jsonstring2;  ?> 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -