Access JSON object name in PHP -
i have following json:
{"nickname":"xadoc","level":4,"loc":"tulsa, ok, usa","score":122597,"money":29412.5,"streetnum":8,"streets":{"-91607259\/387798111":{"name":"alam\u00e9da ant\u00f3nio s\u00e9rgio","value":243,"type":1},"-91016823\/388182402":{"name":"autoestrada norte","value":18304,"type":1},"-86897820\/399032795":{"name":"autoestrada norte","value":12673,"type":1},"-973092846\/479475465":{"name":"19th ave","value":7794,"type":1},"-974473223\/480054888":{"name":"23rd ave ne","value":33977,"type":1}}}
i'm desperately trying access dynamic object names "-91607259\/387798111"
, how can it?
right have:
$jsonurl = "http://www.monopolycitystreets.com/player/stats?nickname=$username&page=1"; $json = file_get_contents($jsonurl,0,null, $obj2 = json_decode($json); foreach ( $obj2->streets $street ) { //here want print "-91607259\/387798111" each street, please //echo $street[0]; gives "fatal error: cannot use object of type stdclass array" //echo $street gives "catchable fatal error: object of class stdclass not converted string" echo '<th>'.$street->name.'</th><td>'."m ".number_format($street->value, 3, ',', ',').'</td>'; }
i imagine simplest thing decode associative arrays instead of stdclass objects
$obj2 = json_decode( $json, true ); foreach ( $obj2['streets'] $coords => $street ) { echo $coords; }
Comments
Post a Comment