Could anyone help me parse this JSON API with PHP? I need to retrieve the currency exchange rate.
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%3D%22eurusd%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=cbfunc
At first you need to omit the last parameter in the URL, just remove
&callback=cbfunc.The PHP code to fetch the content is:
$parsedDatawill now contain the content in a nested object structure.Further info
You need fopen wrappers enabled for this to work. If they are not enabled, just use cURL to load the content from the page and put it into
json_decode.