0

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

I can't get value "Overcast" with my php code :

   echo $data['list'][0]['weather']['description'];
   echo $data['list'][1]['weather']['description'];

...

I tried several combinaison, i read this article How do I extract data from JSON with PHP?

But nothing work...

Community
  • 1
  • 1
logobi
  • 63
  • 1
  • 10

2 Answers2

3

It looks like 'weather' is an array.

Try $data['list'][0]['weather'][0]['description'];

Lasse Sviland
  • 1,479
  • 11
  • 23
0

First, make sure you have decoded the json.

$decodedData = json_decode($data);

Then, try accessing the object's properties and arrays like this:

echo $decodedData->list[0]->weather[0]->description;
JmsBtlr111
  • 31
  • 1
  • 5