解析PHP中的Json openweathermAP

时间:2014-06-13 13:45:42

标签: php json parsing

{
    "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"
                }
            ]
        }
    ]
}

在php中解析这个我能够获取id名称和lon和lat但我无法获得图标... 如何获得图标? 我的代码是:

$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>

SOLUTION:

解决方案是我使用了+而不是。正如评论中指出的那样

  `$url="http://openweathermap.org/img/w/".$k['icon'];` 

0 个答案:

没有答案