在PHP openweatherAPI中解析Json
在php中解析这个,我可以得到id名称、lon和lat,但我不能得到图标。。。 如何获得图标? 我的代码是:在PHP openweatherAPI中解析Json,php,json,parsing,Php,Json,Parsing,在php中解析这个,我可以得到id名称、lon和lat,但我不能得到图标。。。 如何获得图标? 我的代码是: { "message": "accurate", "cod": "200", "count": 1, "list": [ { "id": 2347078, "name": "Birim", "coord": { "lon": 9.9970
{
"message": "accurate",
"cod": "200",
"count": 1,
"list": [
{
"id": 2347078,
"name": "Birim",
"coord": {
"lon": 9.997027,
"lat": 10.062094
},
"main": {
"temp": 307.488,
"temp_min": 307.488,
"temp_max": 307.488,
"pressure": 968.5,
"sea_level": 1022.03,
"grnd_level": 968.5,
"humidity": 61
},
"dt": 1402666090,
"wind": {
"speed": 1.41,
"deg": 263.501
},
"sys": {
"country": ""
},
"clouds": {
"all": 0
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "Sky is Clear",
"icon": "01d"
}
]
}
]
}
$lf=$k['icon']$url=“”;好的,我明白了。。似乎我做对了,只是没有正确放置$url。。愚蠢的我:/n你的问题是
+$k['icon']
。+
符号用于JavaScript连接,您应该使用PHP
而不是使用
进行连接。如果结构总是一样的话。您可以直接访问它$t['list'][0]['weather'][0]['icon']代码>
$lat = $_REQUEST['lat'];
$lng = $_REQUEST['lng'];
$response = file_get_contents("http://api.openweathermap.org/data/2.5/find?lat=$lat&lon=$lng&cnt=10");
$response = json_decode($response, true);
$t = $response['list'];
foreach ($t as $s) {
$w = $s['weather']
foreach ($w as $k) {
$url="http://openweathermap.org/img/w/"+$k['icon'];
}
<img src="<?php echo $url?>" /></p>
`$url="http://openweathermap.org/img/w/".$k['icon'];`