如何使用php获取json值 [英] how to get json value with php
本文介绍了如何使用php获取json值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此处的API参数响应:
Here parameters of API respond :
{"cod":"200","message":0.0045,
"city":{"id":1851632,"name":"Shuzenji",
"coord":{"lon":138.933334,"lat":34.966671},
"country":"JP"},
"cnt":38,
"list":[{
"dt":1406106000,
"main":{
"temp":298.77,
"temp_min":298.77,
"temp_max":298.774,
"pressure":1005.93,
"sea_level":1018.18,
"grnd_level":1005.93,
"humidity":87},
"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],
"clouds":{"all":88},
"wind":{"speed":5.71,"deg":229.501},
"sys":{"pod":"d"},
"dt_txt":"2014-07-23 09:00:00"}
]}
我的php代码无法获得覆盖"的值:
I can't get value "Overcast" with my php code :
echo $data['list'][0]['weather']['description'];
echo $data['list'][1]['weather']['description'];
...
我尝试了几种组合,我读了这篇文章 如何使用PHP从JSON提取数据?
I tried several combinaison, i read this article How do I extract data from JSON with PHP?
但是没有任何作用...
But nothing work...
推荐答案
看起来天气"是一个数组.
It looks like 'weather' is an array.
尝试$data['list'][0]['weather'][0]['description'];
这篇关于如何使用php获取json值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文