Getting data from enumerable JSON subsystems to Javascript without getJSON
I am new to JSON and ajax but I am trying to access data in an array where items are listed in the footer in another sub array. I am having problems trying to access something like
data.items[0].details.specs[1].name
data.items[0].details.specs[1].id
data.items[0].details.specs[2].name
data.items[0].details.specs[2].id
etc
Can anyone point me in the right direction on how to get this right? Thanks.
Update : Here's a clarification to my question with what the JSON response looks like:
{data:{
items: [
{details: {specs:[{name:'something1', id:'something1'},
{name:'something2', id:'something2'},
{name:'something3', id:'something3'},
...
]}}
{details: {specs:[{name:'somethingA', id:'somethingA'},
{name:'somethingB', id:'somethingB'},
{name:'somethingC', id:'somethingC'},
...
]}}
{details: {specs:[{name:'somethingX', id:'somethingX'},
{name:'somethingY', id:'somethingY'},
{name:'somethingZ', id:'somethingZ'},
...
]}}
]}
}
How do I access eg "name: somethingB"?
+2
a source to share
1 answer
Maybe the spec is just not an array of objects.
Your json must be like this to access this path
{
data:{
items: [
{details:
{specs:[
{name:'something1', id:'something1'},
{name:'something2', id:'something2'},
{name:'something3', id:'something3'},
...
]
}
}
]
}
}
Edit . This is a browser cache issue according to the OP
+2
a source to share