{"coord":{"lon":73.69,"lat":17.8},"sys":{"message":0.109,"country":"IN","sunrise":1393032482,"sunset":1393074559},"weather":[{"id":800,"main":"Clear","description":"Sky is Clear","icon":"01n"}],"base":"cmc stations","main":{"temp":293.999,"temp_min":293.999,"temp_max":293.999,"pressure":962.38,"sea_level":1025.86,"grnd_level":962.38,"humidity":78},"wind":{"speed":1.15,"deg":275.503},"clouds":{"all":0},"dt":1393077388,"id":1264491,"name":"Mahabaleshwar","cod":200}
我想从上面的json获取天气的描述,但在php中出现错误。我已经尝试了下面的PHP代码:在PHP中访问JSON值
$jsonDecode = json_decode($contents, true);
$result=array();
foreach($jsonDecode as $data)
{
foreach($data{'weather'} as $data2)
{
echo $data2{'description'};
}
}
任何帮助表示赞赏。我是使用json的新手。
当你尝试时发生了什么?你有错误吗?如果是这样,哪一个?如果你只是想得到天气描述,你可以简单地做:'$ result = $ jsonDecode ['weather'] [0] ['description'];'。 [**查看演示**](https://eval.in/104555) –
您只需调用一次json_deconde。 –
我只打了一次json_decode。 – daman