请帮助我获取JSON结果 - "col1":"64.7020"
到$result
。
{"query":{"count":1,"created":"2016-08-28T09:50:07Z","lang":"ru-RU","diagnostics":{"publiclyCallable":"true","url":{"execution-start-time":"1","execution-stop-time":"2","execution-time":"1","content":"http://finance.yahoo.com/d/quotes.csv?e=.csv&f=c4l1&s=USDRUB=X"},"user-time":"2","service-time":"1","build-version":"0.2.48"},"results":{"row":{"col0":"RUB","col1":"64.7020"}}}}
$tick=file_get_contents('https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url%3D%22http%3A%2F%2Ffinance.yahoo.com%2Fd%2Fquotes.csv%3Fe%3D.csv%26f%3Dc4l1%26s%3DUSDRUB%3DX%22%3B&format=json&diagnostics=true&callback=');
$url = $tick;
$json = file_get_contents($url);
$data = json_decode($json, TRUE);
$result ??
echo col1 ???????
答案 0 :(得分:0)
你已经两次调用了file_get_contents。 $ tick将由yahoo返回json
$tick = file_get_contents('https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url%3D%22http%3A%2F%2Ffinance.yahoo.com%2Fd%2Fquotes.csv%3Fe%3D.csv%26f%3Dc4l1%26s%3DUSDRUB%3DX%22%3B&format=json&diagnostics=true&callback=');
$json_a = json_decode($tick, TRUE);
echo $json_a["query"]["results"]["row"]["col1"];