php and nested json: how can i access this element? -


here's json text:

{ "data": {     "current_condition": [{         "cloudcover": "75",         "humidity": "63",         "observation_time": "03:41 pm",         "precipmm": "0.0",         "pressure": "1020",         "temp_c": "15",         "temp_f": "59",         "visibility": "16",         "weathercode": "116",         "weatherdesc": [{             "value": "partly cloudy"         }],         "weathericonurl": [{             "value": "http:\/\/cdn.worldweatheronline.net\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png"         }],         "winddir16point": "sse",         "winddirdegree": "160",         "windspeedkmph": "7",         "windspeedmiles": "4"     }],     "request": [{         "query": "northville, united states of america",         "type": "city"     }],     "weather": [{         "date": "2013-09-24",         "precipmm": "0.0",         "tempmaxc": "20",         "tempmaxf": "67",         "tempminc": "8",         "tempminf": "47",         "weathercode": "113",         "weatherdesc": [{             "value": "sunny"         }],         "weathericonurl": [{             "value": "http:\/\/cdn.worldweatheronline.net\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png"         }],         "winddir16point": "ese",         "winddirdegree": "111",         "winddirection": "ese",         "windspeedkmph": "10",         "windspeedmiles": "6"     }] } 

}

i'm trying echo 'temp_f' , not working. can't figure out i'm doing wrong. far:

$url = file_get_contents("http://blahblahblahblah"); $arr = json_decode($url,true); 

and that's fails. i've done var_dump's know data there. every 'echo' attempt i've tried results in 'array' being displayed screen. i've tried many variations of following:

echo $arr->{'data'}->{'current_condition[0]'}->{'temp_f'}; 

can tell me i'm doing wrong? thanks!

json_decode() true second parameter gives associative array. you're trying access object.

try following:

echo $arr['data']['current_condition'][0]['temp_f']; 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -