【发布时间】:2013-11-18 09:44:22
【问题描述】:
我正在处理来自 wunderground.com 的 json 源代码。作为文档中显示的示例代码。我可以调整和锻炼一些简单的格式。但我坚持这个。我试图用谷歌搜索每个地方,但没有解决方案。
以下是示例代码:
<?php
$json_string = file_get_contents("http://api.wunderground.com/api/b8e924a8f008b81e/geolookup/conditions/q/IA/Cedar_Rapids.json");
$parsed_json = json_decode($json_string);
$location = $parsed_json->{'location'}->{'city'};
$temp_f = $parsed_json->{'current_observation'}->{'temp_f'};
echo "Current temperature in ${location} is: ${temp_f}\n";
?>
嗯,我需要一些信息,例如 pws/station 中的“Cedar Rapids”:
"pws": {
"station": [
{
"neighborhood":"Ellis Park Time Check",
"city":"Cedar Rapids",
"state":"IA",
"country":"US",
"id":"KIACEDAR22",
"lat":41.981174,
"lon":-91.682632,
"distance_km":2,
"distance_mi":1
}
]
}
(您可以点击这里获取所有代码:http://api.wunderground.com/api/b8e924a8f008b81e/geolookup/conditions/q/IA/Cedar_Rapids.json) 现在的问题是:
- 这个数据叫什么? (数组,数组中的数组?)
- 如何才能将这些数据提取出来?
问候,
【问题讨论】:
标签: php arrays json wunderground