如何从JavaScript中的URL获取JSON?
此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('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
});
以上是 如何从JavaScript中的URL获取JSON? 的全部内容, 来源链接: utcz.com/qa/419372.html