【发布时间】:2019-09-20 13:09:22
【问题描述】:
有一个 API 的结果是这样的:
// 20190920173100
//api.opencagedata.com/geoc
{
"documentation": "https://opencagedata.com/api",
"licenses": [
{
"name": "see attribution guide",
"url": "https://opencagedata.com/credits"
}
],
"rate": {
"limit": 2500,
"remaining": 2493,
"reset": 1569024000
},
"results": [
{
"bounds": {
"northeast": {
"lat": 51.9528202,
"lng": 7.6325938
},
"southwest": {
"lat": 51.9525445,
"lng": 7.6323594
}
},
"components": {
"ISO_3166-1_alpha-2": "DE",
"ISO_3166-1_alpha-3": "DEU",
"_type": "building",
"city": "Münster",
"city_district": "Münster-Mitte",
"continent": "Europe",
"country": "Germany",
"country_code": "de",
"county": "Münster",
"house_number": "7",
"neighbourhood": "Josef",
"political_union": "European Union",
"postcode": "48153",
"road": "Friedrich-Ebert-Straße",
"state": "North Rhine-Westphalia",
"state_district": "Regierungsbezirk Münster",
"suburb": "Innenstadtring"
},
"confidence": 10,
"formatted": "Friedrich-Ebert-Straße 7, 48153 Münster, Germany",
"geometry": {
"lat": 51.9526599,
"lng": 7.632473
}
}
],
"status": {
"code": 200,
"message": "OK"
},
"stay_informed": {
"blog": "https://blog.opencagedata.com",
"twitter": "https://twitter.com/opencagedata"
},
"thanks": "For using an OpenCage API",
"timestamp": {
"created_http": "Fri, 20 Sep 2019 13:01:02 GMT",
"created_unix": 1568984462
},
"total_results": 1
}
我想用上面的数据。
我尝试了以下代码:
$adress = json_decode(file_get_contents("https://api...."));
$detail = $adress ->rate->limit;
没关系
问题是当我使用此代码获取结果数据时,例如它为空
$adress = json_decode(file_get_contents("https://api...."));
$detail = $adress ->result>formatted;
我猜是因为对象和数组的原因
【问题讨论】:
-
你的 json 有 no
result属性。 -
"结果" != "结果"