1

I have the following Json data. I want to access the single value "temp" in "main" but I can't figure out how do to it. I've been trying for 2 hours now but no success so far, so help would be very much appreciated.

   {  
   "message":"accurate",
   "cod":"200",
   "count":1,
   "list":[  
      {  
         "id":2939944,
         "name":"Dülmen",
         "coord":{  
            "lat":51.8284,
            "lon":7.2791
         },
         "main":{  
            "temp":8,
            "pressure":1009,
            "humidity":81,
            "temp_min":7,
            "temp_max":9
         },
         "dt":1522923600,
         "wind":{  
            "speed":8.2,
            "deg":250,
            "gust":13.4
         },
         "sys":{  
            "country":"DE"
         },
         "rain":null,
         "snow":null,
         "clouds":{  
            "all":90
         },
         "weather":[  
            {  
               "id":804,
               "main":"Clouds",
               "description":"overcast clouds",
               "icon":"04d"
            }
         ]
      }
    ]
   }
Peter P
  • 83
  • 1
  • 7

1 Answers1

2

You can use json_decode()

This converts JSON into an object

   $data = json_decode($data);
   print_r($data->list[0]->main->temp);

This converts JSON into Array

$data = json_decode($data, true);
print_r($data['list'][0]['main']['temp']);
Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71