I have the following string:
[{"EventType":1,"ParticipantId":"1","X":123,"Y":123},{"EventType":2,"ParticipantId":"1","ParrentList":[123,124,125,126],"X":0,"Y":0}]
Could anybody give me an idea on how to convert this into a JSON structure and then get the value of each key, say:
EventType = 1;
ParticipantId = 1;
X = 123;
etc.
I'm actually trying to do it as follows, but I don't think that this is a smart way of doing that:
var results = [{"EventType":1,"ParticipantId":"1","X":123,"Y":123},{"EventType":2,"ParticipantId":"1","ParrentList":[123,124,125,126],"X":0,"Y":0}];
var arr = eval("(" + results + ')');
for(var i=0;i<arr.length;i++){
var obj = arr[i];
for(var key in obj) {
var attrName = key;
var attrValue = obj[key];
switch(attrName) {
case "EventType" :
EventType = attrValue;
break;
case "ParticipantId" :
ParticipantId = attrValue;
break;
case "X" :
xCoord = attrValue;
break;
case "Y" :
yCoord = attrValue;
break;
}
}
}
Thanks.
var results =
assignment in your Javascript?