需要从嵌套数组对象中分配变量(Need to assign variables from nested array object)
我确信我在这里遗漏了一些简单的东西,但是在从包含多个嵌套数组的对象中获取值时遇到了麻烦。
这是分配的对象:
$obj = json_decode($uri); // Convert JSON这是来自此对象的print_r:
Array ( [0] => stdClass Object ( [total] => 1 [results] => Array ( [0] => stdClass Object ( [coordinates] => Array ( [0] => -88.359306 [1] => 41.685747 ) [country_id] => US [state_id] => IL [address_locality] => Oswego [address_text] => 201Washington St [street_number] => 201 [street_name] => Washington St [confidence] => 0.71 [county_id] => 17093 [_type] => geo.place [geo_geometry_type] => Point ) ) ) )我无法获得county_id,坐标等的值...
我试图使用像$ obj-> results [0] - > coordinates [0] ....但这没有用
I am sure I am missing something simple here but am having trouble grabbing values from an object that contains several nested arrays.
Here is the object being assigned:
$obj = json_decode($uri); // Convert JSONHere is the print_r from this object:
Array ( [0] => stdClass Object ( [total] => 1 [results] => Array ( [0] => stdClass Object ( [coordinates] => Array ( [0] => -88.359306 [1] => 41.685747 ) [country_id] => US [state_id] => IL [address_locality] => Oswego [address_text] => 201Washington St [street_number] => 201 [street_name] => Washington St [confidence] => 0.71 [county_id] => 17093 [_type] => geo.place [geo_geometry_type] => Point ) ) ) )I am having trouble getting at the values for county_id, coordinates, etc...
I was trying to use something like $obj->results[0]->coordinates[0].... but this didnt work
最满意答案
你只是在$ obj之后错过了[0]吗?
$obj[0]->results[0]->coordinates[0]Are you just missing the [0] after $obj?
$obj[0]->results[0]->coordinates[0]更多推荐
发布评论