我从 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/