此URL返回JSON:
{ query: { count: 1, created: "2015-12-09T17:12:09Z", lang: "en-US", diagnostics: {}, ... } }
我尝试了一下,但没有成功:
responseObj = readJsonFromUrl('http://query.yahooapis.com/v1/publ...'); var count = responseObj.query.count; console.log(count) // should be 1
如何从该URL的JSON响应中获取JavaScript对象?
您可以使用jQuery .getJSON()函数:
.getJSON()
$.getJSON('http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20yahoo.finance.quotes%20WHERE%20symbol%3D%27WRC%27&format=json&diagnostics=true&env=store://datatables.org/alltableswithkeys&callback', function(data) { //data is the JSON string });