当我尝试使用以下方法从API获取数据时
file_get_contents("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22USDINR%22)&format=json&env=store://datatables.org/alltableswithkeys&callback=");
我得到的结果是字符串。有什么办法可以将其转换回数组吗?我得到的字符串是
string(202) "{"query":{"count":1,"created":"2014-03-11T13:00:31Z","lang":"en-US","results":{"rate":{"id":"USDINR","Name":"USD to INR","Rate":"60.99","Date":"3/11/2014","Time":"9:00am","Ask":"61.00","Bid":"60.98"}}}}"{"error":"","msg":""}
请帮我....
在您的请求中,您要求对返回的格式进行JSON
编码(通过format=json
参数),因此您可以使用json_decode
以下命令将响应解码为数组:
$response = file_get_contents("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22USDINR%22)&format=json&env=store://datatables.org/alltableswithkeys&callback=");
$response = json_decode($response, true);
// Parse the array as you would any other
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句