javascript - 如何导航并获取 URL 中的特定 json 对象?

标签 javascript php jquery json

我从 url 获取 json,但它有很多对象,我如何才能只获取给出下面提供的 json 的 slugs?

我不介意在 php 或 js 中使用它,我的意思是一方面我需要知道如何使用 php 或 js 获取我想要的对象,另一方面我想知道我们是否可以获取一个对象在 url 中提供参数

[  
   {  
      "id":580,
      "count":0,
      "description":"qwer",
      "link":"http:\/\/example.com\/ing\/category\/persone\/414qwer1324r-qewr1233423\/",
      "name":"414qwer1324r qewr1233423",
      "slug":"414qwer1324r-qewr1233423",
      "taxonomy":"category",
      "parent":183,
      "meta":[  

      ],
      "_links":{  
         "self":[  
            {  
               "href":"http:\/\/example.com\/ing\/wp-json\/wp\/v2\/categories\/580"
            }
         ],
         "collection":[  
            {  
               "href":"http:\/\/example.com\/ing\/wp-json\/wp\/v2\/categories"
            }
         ],
         "about":[  
            {  
               "href":"http:\/\/example.com\/ing\/wp-json\/wp\/v2\/taxonomies\/category"
            }
         ],
         "up":[  
            {  
               "embeddable":true,
               "href":"http:\/\/example.com\/ing\/wp-json\/wp\/v2\/categories\/183"
            }
         ],
         "wp:post_type":[  
            {  
               "href":"http:\/\/example.com\/ing\/wp-json\/wp\/v2\/posts?categories=580"
            }
         ],
         "curies":[  
            {  
               "name":"wp",
               "href":"https:\/\/api.w.org\/{rel}",
               "templated":true
            }
         ]
      }
   },
   {  
      "id":586,
      "count":1,
      "description":"asdfasd",
      "link":"http:\/\/example.com\/ing\/category\/persone\/add-person\/",
      "name":"Add person",
      "slug":"add-person",
      "taxonomy":"category",
      "parent":183,
      "meta":[  

      ],
      "_links":{  
         "self":[  
            {  
               "href":"http:\/\/example.com\/ing\/wp-json\/wp\/v2\/categories\/586"
            }
         ],
         "collection":[  
            {  
               "href":"http:\/\/example.com\/ing\/wp-json\/wp\/v2\/categories"
            }
         ],
         "about":[  
            {  
               "href":"http:\/\/example.com\/ing\/wp-json\/wp\/v2\/taxonomies\/category"
            }
         ],
         "up":[  
            {  
               "embeddable":true,
               "href":"http:\/\/example.com\/ing\/wp-json\/wp\/v2\/categories\/183"
            }
         ],
         "wp:post_type":[  
            {  
               "href":"http:\/\/example.com\/ing\/wp-json\/wp\/v2\/posts?categories=586"
            }
         ],
         "curies":[  
            {  
               "name":"wp",
               "href":"https:\/\/api.w.org\/{rel}",
               "templated":true
            }
         ]
      }
   },
   {  
      "id":520,
      "count":8,
      "description":"",
      "link":"http:\/\/example.com\/ing\/category\/argomenti\/amici\/",
      "name":"AMICI",
      "slug":"amici",
      "taxonomy":"category",
      "parent":184,
      "meta":[  

我如何获得所有“slug”:”的列表,其值如网址中的“slug”:“amici”?

http://example.com/ing/wp-json/wp/v2/categories/names

最佳答案

在 JavaScript 中,您可以使用 Array.prototype.map() 和解构赋值

let res = data.map(({slug}) => slug)

关于javascript - 如何导航并获取 URL 中的特定 json 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54735652/

相关文章:

javascript - 如何将removePostDataItem与新的jqgrid一起使用

javascript - 如何显示未填写的字段

javascript - () => {} 在 gulpfile.js 中是什么意思

javascript - 如何将数组传递到另一个页面

php - 使用 MySQL PHP 显示投资组合项目的信息并显示多个类别

javascript - 使用断线复制到剪贴板

javascript - 使用 Google Maps JS API 随机拖动/平移

php - Wordpress 短代码在错误的地方

php - jQuery/php/mysql - 如何在不重新加载页面的情况下操作 mysqli_query?

php - 来自 PHP 的 jQuery 的 AJAX 响应有困难