Get JSON objects in PHP, not array -
im writing website in php gets jsonstring php-api ive created. string looks this:
{ "result": "true", "results": { "20": { "id": "20", "desc": "a b ct tr", "active": "1", "startdate": "2013-04-03", "starttimehour": "18", "starttimemin": "0", "enddate": "2013-04-03", "endtimehour": "22", "endtimemin": "0", "creator": "a" }, "21": { "id": "21", "desc": "test", "active": "0", "startdate": "2013-04-04", "starttimehour": "18", "starttimemin": "0", "enddate": "2013-04-04", "endtimehour": "22", "endtimemin": "0", "creator": "a" } } }
ive found lots of answers on how information jsonarray im not using array here. question is: how can objects labeled 20, 21 , forth(these numbers generated server dont know ones returned).
or should rewrite how api returns json array instead. this:
{"result"="true", "results":[{...},{...},{...}]}
$json = json_decode($json_string, true); foreach($json['results'] $key => $value) { // access number $key , associated object $value echo 'number: '.$key; echo 'startdate: '.$value['startdate']; }
Comments
Post a Comment