Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

javascript - 如何从JavaScript中的URL获取JSON?(How to get JSON from URL in JavaScript?)

This URL returns JSON:(此URL返回JSON:)

{ query: { count: 1, created: "2015-12-09T17:12:09Z", lang: "en-US", diagnostics: {}, ... } } I tried this, and it didn't work:(我尝试了一下,但没有成功:) responseObj = readJsonFromUrl('http://query.yahooapis.com/v1/publ...'); var count = responseObj.query.count; console.log(count) // should be 1 How can I get a JavaScript object from this URL's JSON response?(如何从该URL的JSON响应中获取JavaScript对象?)   ask by Yi?it Do?u? ?z?elik translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use jQuery .getJSON() function:(您可以使用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 }); If you don't want to use jQuery you should look at this answer for pure JS solution: https://stackoverflow.com/a/2499647/1361042(如果您不想使用jQuery,则应该查看以下答案以获得纯JS解决方案: https : //stackoverflow.com/a/2499647/1361042)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...