如何从 json 对象解析 json 数组?
How can I parse json array from json object?
我有一个 json 对象从 reactjs 中的 get 请求返回。我想从中获取关键和有价值的项目。
{"return":"Success",
"Items": [
{"Name":"centracore", "Type":"rollover" , "Os":"Windows", "Level":"1", "Language_Used":"Assembly", "Size":"4mb"},
{"Name":"centracore", "Type":"Atype" , "Os":"Linux" , "Level":"3", "Language_Used":"C++" , "Size":"4mb"},
{"Name":"centracore", "Type":"random" , "Os":"OSX" , "Level":"2", "Language_Used":"C" , "Size":"4mb"}
]}
我注意到我可以使用下面的代码手动访问这些值。
请记住,this.state.stuff 持有我的 json 对象。我的格式 json 格式对我想做的事情不好吗?
if(this.state.authenticated ){
{this.GetPage.bind(this)}
let x = this.state.stuff; Object.entries(this.state.stuff).map((type,item) => {
console.log(type[1][0])
console.log(type[1][1])
console.log(type[1][2])
})
据我了解,您希望能够获取对象项数组中的键和值,因此您需要映射项数组,然后使用 [= 从获得的项中映射 key, values
13=]
你可以这样做
if(this.state.authenticated ){
{this.GetPage.bind(this)}
this.state.stuff.Items.map((item, index) => {
Object.entries(item).forEach([key, value], () => {
console.log(key, value)
})
})
工作示例
var obj = {"return":"Success",
"Items": [
{"Name":"centracore", "Type":"rollover" , "Os":"Windows", "Level":"1", "Language_Used":"Assembly", "Size":"4mb"},
{"Name":"centracore", "Type":"Atype" , "Os":"Linux" , "Level":"3", "Language_Used":"C++" , "Size":"4mb"},
{"Name":"centracore", "Type":"random" , "Os":"OSX" , "Level":"2", "Language_Used":"C" , "Size":"4mb"}
]}
obj.Items.map((item, index) => {
console.log( item);
Object.entries(item).forEach(([key, value]) => {
console.log(key, value)
})
})
我有一个 json 对象从 reactjs 中的 get 请求返回。我想从中获取关键和有价值的项目。
{"return":"Success",
"Items": [
{"Name":"centracore", "Type":"rollover" , "Os":"Windows", "Level":"1", "Language_Used":"Assembly", "Size":"4mb"},
{"Name":"centracore", "Type":"Atype" , "Os":"Linux" , "Level":"3", "Language_Used":"C++" , "Size":"4mb"},
{"Name":"centracore", "Type":"random" , "Os":"OSX" , "Level":"2", "Language_Used":"C" , "Size":"4mb"}
]}
我注意到我可以使用下面的代码手动访问这些值。
请记住,this.state.stuff 持有我的 json 对象。我的格式 json 格式对我想做的事情不好吗?
if(this.state.authenticated ){
{this.GetPage.bind(this)}
let x = this.state.stuff; Object.entries(this.state.stuff).map((type,item) => {
console.log(type[1][0])
console.log(type[1][1])
console.log(type[1][2])
})
据我了解,您希望能够获取对象项数组中的键和值,因此您需要映射项数组,然后使用 [= 从获得的项中映射 key, values
13=]
你可以这样做
if(this.state.authenticated ){
{this.GetPage.bind(this)}
this.state.stuff.Items.map((item, index) => {
Object.entries(item).forEach([key, value], () => {
console.log(key, value)
})
})
工作示例
var obj = {"return":"Success",
"Items": [
{"Name":"centracore", "Type":"rollover" , "Os":"Windows", "Level":"1", "Language_Used":"Assembly", "Size":"4mb"},
{"Name":"centracore", "Type":"Atype" , "Os":"Linux" , "Level":"3", "Language_Used":"C++" , "Size":"4mb"},
{"Name":"centracore", "Type":"random" , "Os":"OSX" , "Level":"2", "Language_Used":"C" , "Size":"4mb"}
]}
obj.Items.map((item, index) => {
console.log( item);
Object.entries(item).forEach(([key, value]) => {
console.log(key, value)
})
})