读取 jsonp api 调用返回的 json 对象
Read the json object returned by jsonp api call
这是 api 我正在打电话:
https://api.github.com/search/repositories?q=language:python&sort=stars
return 最高星标 python 项目并在通过浏览器触发时显示。
但是当我尝试从代码访问 json 键时,它说未定义。
我做错了什么?
$.getJSON("https://api.github.com/search/repositories?q=language:python&sort=stars&callback=?", function(result){
alert(typeof(result));
alert(result.total_count);
alert(result.incomplete_results);
});
只需从 url 中删除回调:
$.getJSON("https://api.github.com/search/repositories?q=language:python&sort=stars", function(result){
alert(typeof(result));
alert(result.total_count);
alert(result.incomplete_results);
});
这是一个有效的 fiddle:
https://jsfiddle.net/a9npgduz/
这是 api 我正在打电话: https://api.github.com/search/repositories?q=language:python&sort=stars return 最高星标 python 项目并在通过浏览器触发时显示。 但是当我尝试从代码访问 json 键时,它说未定义。 我做错了什么?
$.getJSON("https://api.github.com/search/repositories?q=language:python&sort=stars&callback=?", function(result){
alert(typeof(result));
alert(result.total_count);
alert(result.incomplete_results);
});
只需从 url 中删除回调:
$.getJSON("https://api.github.com/search/repositories?q=language:python&sort=stars", function(result){
alert(typeof(result));
alert(result.total_count);
alert(result.incomplete_results);
});
这是一个有效的 fiddle: https://jsfiddle.net/a9npgduz/