javascript - 如何在 URL 中导航和获取特定的 json 对象?
问题描述
我从一个 url 得到一个 json,但它有很多对象,我怎么才能只得到下面提供的 json 的蛞蝓?
我不介意在 php 或 js 中,我的意思是一方面我需要知道如何使用 php 或 js 获取我想要的对象,另一方面我想知道我们是否可以获得提供参数的对象在网址中
[
{
"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”的列表:”它们的值如 url 中的“slug”:“amici”?
喜欢http://example.com/ing/wp-json/wp/v2/categories/names
解决方案
在 JavaScript 中,您可以使用Array.prototype.map()
和解构赋值
let res = data.map(({slug}) => slug)
推荐阅读
- asp.net - TypeScript - [后续属性声明必须具有相同的类型] - 对相同类型定义的多次引用
- .net - 重启系统后redis密码丢失
- linux - 如何在 Linux 中使用 grep 找出一行中的单词?
- matlab - 我需要创建一个对角矩阵,其中对角元素是一个向量
- typescript - 打字稿不能破坏联合类型
- javascript - Amazon AWS SDK MediaConvert 不是构造函数
- elasticsearch - 仅限 Percolator 的弹性搜索集群 - 是否值得拥有专用的主节点?
- android - RecyclerView android studio的渲染问题
- javascript - 鼠标悬停的手风琴孩子
- javascript - VueJS v-for inside 组件模板似乎没有循环