I created a JSON variable and parsing it to JSON. But I am not able to read the values. I tried everything. But its not working. Here is my JavaScript code.
var graph='{"graphSpace":[{"rectangle":{"minX":0.0,"minY":0.0,"maxX":0.0,"maxY":0.0},"contents":"","rights":[],"lefts":[],"tops":[],"downs":[],"annotation":{"id":255,"type":"line"}],[{"rectangle":{"minX":174.0,"minY":87.0,"maxX":989.0,"maxY": 136.0},"contents":"Carter Brothers Fire u0026 Life Safety","rights":[{"id":59}],"lefts":[],"tops":[{"id":255}],"downs":[{"id":14},{"id":16},{"id":19},{"id":21},{"id":28},{"id":31},{"id":33},{"id":35},{"id":42},{"id":45},{"id":47},{"id":49},{"id":52},{"id":183},{"id":169},{"id":199},{"id":190},{"id":201},{"id":192},{"id":208},{"id":215},{"id":230},{"id":233},{"id":240},{"id":243},{"id":246}],"annotation":{"id":7,"type":"line"}},{"rectangle":{"minX":2073.0,"minY":92.0,"maxX":2327.0,"maxY":150.0},"contents":"Invoice","rights":[],"lefts":[{"id":7}],"tops":[{"id":7},{"id":255}],"downs":[{"id":67},{"id":70},{"id":72},{"id":74},{"id":76},{"id":100},{"id":102},{"id":105},{"id":108},{"id":111},{"id":114},{"id":135},{"id":160},{"id":151},{"id":162},{"id":153},{"id":264},{"id":280},{"id":302}],"annotation":{"id":59,"type":"line"}}]}';
For your convenience, I'll put the data in a readable format.
{
"graphSpace":
[
{"rectangle":
"{ "minX": 0.0, "minY": 0.0, "maxX": 0.0, "maxY":0.0}",
"contents":"",
"rights":"[]",
"lefts":"[]",
"tops":"[]",
"downs":"[]",
"annotation":
"{ "id": 255, "type": "line"}"
],
[
{"rectangle":
"{ "minX": 174.0, "minY": 87.0, "maxX": 989.0, "maxY": 136.0}",
"contents":"JSON u0026 JAVASCRIPT",
"rights":"
[{"id":59}]",
"lefts":"[]",
"tops":"[{"id":255}]",
"downs":"
[{"id":14},]",
"annotation":
"{ "id": 7, "type": "line"}"
},
{"rectangle":
"{ "minX": 2073.0, "minY": 92.0, "maxX": 2327.0, "maxY":150.0}",
"contents":"JSON EXample",
"rights":"[]",
"lefts":
"[{"id":7}]",
"tops":
"[{"id":7},{"id":255}]",
"downs":
"[{"id":67},{"id":70},{"id":72},]",
"annotation":
"{"id": 59, "type": "line"}"
}
]
}
Now I am creating a variable which will store the parsed data. Then I am checking whether it stored or not. So i am reading the first value and alerting it.
var graphSpace=JSON.parse(graph);
var minx = graphSpace[0].rectangle.minX;
alert(minx);
But when i open this JSP page, I am not able to get see that alert. What is the mistake here?
Update: Sorry I forgot to add the first key when I was copying. Please check it