检索JSON值不起作用

编程入门 行业动态 更新时间:2024-10-23 16:27:13
检索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> 
  
 

更多推荐

本文发布于:2023-08-07 07:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1462636.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!