This is my JavaScript object:
{
"A":{
"B":[{
"C":{
"D":[{
"test" : "Hello"
}]
}
}]
}
}
From this how do I store objects B and C in a variable?
This is my JavaScript object:
{
"A":{
"B":[{
"C":{
"D":[{
"test" : "Hello"
}]
}
}]
}
}
From this how do I store objects B and C in a variable?
If ob
is the object representation of the JSON, ob.A.B
should give you B
. And notice that ob.A.B
is an array containing one object with key C
. Hence C
can be accessed as ob.A.B[0].C
, the first element of the array.
Should be as simple as
var a = {
"A":{
"B":[{
"C":{
"D":[{
"test" : "Hello"
}]
}
}]
}
};
console.log( a.A.B ); //print the value of B
console.log( a.A.B[0].C ); //print the value of C
suppose we are storing your json into a variable data
data.A.B will give you Object B
and
data.A.B[0].C will give you Object C