This 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) {
// JSON result in `data` variable
});
如果您不想使用 jQuery,您应该查看 this answer纯JS解决方案。
https://stackoverflow.com/questions/12460378/