After creating a JSON object and storing it in MySQL, I encountered an issue when trying to retrieve and parse it. When I stringify the JSON object, the properties are being enclosed in double quotes causing issues when parsing the retrieved string. Below is the code snippet:
for(var i=0;i<objects.length;i++){
var o=new Object();
var id=objects[i].userData.id;
var name=objects[i].name;
o.id=id;
o.x=objects[i].position.x;
o.y=objects[i].position.y;
o.z=objects[i].position.z;
o.r=objects[i].rotation.z;
resources[name]=o;
}
I save JSON.stringify(resources)
into MySQL, resulting in a string like
{"animalsherd0":{"id":"11","x":"4.7","y":"19.6","z":"18.8","r":0},"oasis1":{"id":"19","x":"-11.3","y":"19.6","z":"18.8","r":0},"corn2":{"id":"24","x":"-5.6","y":"19.6","z":"5.0","r":0}}
The retrieved string is stored in a variable. How can I effectively parse this string?