I have the following json response from server:
$data=[[
{"left":{"p1":{"x":0,"y":0},"p2":{"x":0,"y":15}},
"right":{"p1":{"x":15,"y":0},"p2":{"x":15,"y":15}},
"up":{"p1":{"x":0,"y":0},"p2":{"x":15,"y":0}},
"bottom":{"p1":{"x":0,"y":15},"p2":{"x":15,"y":15}}},
{"left":{"p1":{"x":0,"y":15},"p2":{"x":0,"y":30}},
"right":{"p1":{"x":15,"y":15},"p2":{"x":15,"y":30}},
"up":{"p1":{"x":0,"y":15},"p2":{"x":15,"y":15}},
"bottom":{"p1":{"x":0,"y":30},"p2":{"x":15,"y":30}}}
],
[
{"left":{"p1":{"x":0,"y":0},"p2":{"x":0,"y":15}},
"right":{"p1":{"x":15,"y":0},"p2":{"x":15,"y":15}},
"up":{"p1":{"x":0,"y":0},"p2":{"x":15,"y":0}},
"bottom":{"p1":{"x":0,"y":15},"p2":{"x":15,"y":15}}},
{"left":{"p1":{"x":0,"y":15},"p2":{"x":0,"y":30}},
"right":{"p1":{"x":15,"y":15},"p2":{"x":15,"y":30}},
"up":{"p1":{"x":0,"y":15},"p2":{"x":15,"y":15}},
"bottom":{"p1":{"x":0,"y":30},"p2":{"x":15,"y":30}}}
]
]
I would like to alert every x of p1 point in left.
$.getJSON("jetData",
function(data) {
$.each(data, function(i,item){
alert(data[i].left.p1.x);
});
});
I'm getting
Uncaught TypeError: Cannot read property 'p1' of undefined
How to do it correct?
Update:
I'm sorry I posted wrong example it just took me some time to realize that we are talking about 2x2 matrix. so I need to print value in 2 loops.