我将如何访问这里面数据的JSON数组用PHP的? [英] How would I access this data inside of a JSON array with PHP?
问题描述
我试图访问一个JSON数组里面一定阵,我似乎无法弄清楚如何访问这些数据,任何帮助将是AP preciated!
I am trying to access a certain array inside of a JSON array, I can not seem to figure out how to access this data, any help would be appreciated!
下面是JSON数组: https://gist.github.com/anonymous/a37852a7436d31289390
Here is the JSON array: https://gist.github.com/anonymous/a37852a7436d31289390
它没有唯一的标识符,这就是为什么我无法访问它。
It has no unique identifier, thats why I'm having trouble accessing it.
推荐答案
假设你想从这个JSON数据访问的国家名称。与已存储在 $地理code 变量,然后,你可以做以下JSON数据。这会给你的关键,其关键的名字是国家的精确值,无论哪个指数是的。
Suppose you want to access country name from this json data. and you have stored that json data in $geocode variable, Then you can do following. This will give you exact value of key whose key name is country, no matter on which index it is.
$输出= json_de code($地理code);
$output= json_decode($geocode);
foreach($output->results[0]->address_components as $key=>$val)
{
if($val->types[0]=='country' || $val->types[1]=='country')
{
$country=$output->results[0]->address_components[$key]->long_name;
}
}
如果您确定要索引值就可以接取它下面
If you are sure about index value you can acess it as below
$国家= $输出 - >结果[0] - > address_components [5] - > LONG_NAME;
$country =$output->results[0]->address_components[5]->long_name;
希望这有助于:)
这篇关于我将如何访问这里面数据的JSON数组用PHP的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!