I have the next array json, How could I read it?
I already tried with document.write(arr)
, and it works, but If I put document.write(arr[0].Category)
it shows undefined
,
var arr = [{"Category":
{"cell":{"question1":{"que1":"What is the cell?"},
"option1":{"op1":"The cell is the basic structural and functional unit",
"op2":"is a fictional supervillain in Dragon Ball"},"answer1":"opt1"}}},
{"Category":{"Mars":{"question1":{"que1":"How many moons does Mars?"},
"option1":{"op1":"5","op2":"2"},"answer1":"opt2"}}}]
By the way the array is well formet, because if I do document.write(arr)
it return the same array
document.write()
is not the best way to inspect variables. Useconsole.log()
instead.arrjson[0].Category
instead.arr
is a string.var arr = JSON.stringify(arrjson)
? This conflicts with the code you have given.