Some help to parse a json file with php

Monkey Archive Forums/Monkey Discussion/Some help to parse a json file with php

hub(Posted 2016) [#1]
Hi !
I'm searching a way to parse a json file with php and display the 'fcttext' value


(all the json output here :

http://api.wunderground.com/api/b99efd866a7db36a/forecast/lang:FR/q/FR/Castelnaudary.json

)

So i've this php code :


But i've not the value of fcttext inside $weather !
I'm not familiar with json_decode function !

Thanks for your help


muddy_shoes(Posted 2016) [#2]
In the json you provide "forecastday" is a json array element, not an object, and the bit you're after is within "txt_forecast", not just "forecast". I'd imagine in the PHP output you'd need to deference the specific period element you want, so something like:

$parsed_json->{"forecast"}->{"txt_forecast"}->{"forecastday"}[0]->{"fcttext"}



hub(Posted 2016) [#3]
Works fine now. Many thanks muddy_shoes.