检索JSON值不起作用 - JavaScript / jQuery(Retrieving JSON Values Not Working - JavaScript/jQuery)
下面是我用来从API检索某个字体名称的代码(其中包含可用字体列表)。
问题是我只能检索前20个值。 通过在此之后将19更改为任何数字,不会检索family值。
$.getJSON("https://www.googleapis.com/webfonts/v1/webfonts?key=***", function(result){ $.each(result, function(i, field){ $("div").append([field][0][19]['family']); }); });这是一个小例子:
https://jsfiddle.net/tLhea2eo/2/
Below is the code that I am using to retrieve a certain font name from the API (which contains a list of fonts available).
The problem is that I am only able to retrieve the first 20 values. By changing the 19 to any number after that, the family value is not retrieved.
$.getJSON("https://www.googleapis.com/webfonts/v1/webfonts?key=***", function(result){ $.each(result, function(i, field){ $("div").append([field][0][19]['family']); }); });Here is an example fiddle:
https://jsfiddle.net/tLhea2eo/2/
最满意答案
所有字体都在数组result.items ,长度为82
$.getJSON("https://www.googleapis.com/webfonts/v1/webfonts?key=***", function(result) { $.each(result.items, function(i, item) { $("ul").append('<li>' + item.family + '</li>'); }); });<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul></ul>All the fonts are in the array result.items which has length of 82
$.getJSON("https://www.googleapis.com/webfonts/v1/webfonts?key=***", function(result) { $.each(result.items, function(i, item) { $("ul").append('<li>' + item.family + '</li>'); }); });<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul></ul>
更多推荐
发布评论