[英]How to navigate and get a specific json object in URL?
I getting a json from a url but it has lots of objects, how would I only get the slugs giving the json provided below? 我从网址中获取json,但其中包含许多对象,我如何仅获得下面提供的json的子弹?
I don't mind it either in php or js, I mean on the one hand I need to know how to get what object I want using php or js, on the other hand I am wondering if we can get an object providing a parameter in the url 我不在乎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":[
How would I get a list of all "slug":" with their value like "slug":"amici" in a url? 如何在网址中获取所有“ slug”:”的列表,其值类似于“ slug”:“ amici”?
Like http://example.com/ing/wp-json/wp/v2/categories/names
像http://example.com/ing/wp-json/wp/v2/categories/names
在JavaScript中,您可以使用Array.prototype.map()
和解构分配
let res = data.map(({slug}) => slug)
You can use map and destructuring assignment 您可以使用地图和销毁任务
let data = [{"id":580,"count":0,"description":"qwer","link":"http:\\/\\/example.com\\/ing\\/category\\/persone\\/414qwer1324r-qewr1233423\\/","name":"414qwer1324rqewr1233423","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":"Addperson","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}]}}] let op = data.map(({slug})=> slug ) console.log(op)
在PHP中,您可以使用array_column函数:
$slugs = array_column($posts, 'slug');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.