I am storing some coordinates in a database, I do this using JSON.stringify method to convert an array of coords into a string. This works fine but when I try to reload the coords using JSON.parse() I don't get the original coords back instead I get [object Object],[object Object].
here is the code.
var str = JSON.stringify(path);
document.dataForm.routeMarkers.value = str;
this converts an array of coords eg (51.50439265195253, -3.3535325679687276),(51.53259269613245, -3.2134568843749776)
var loadStr = document.dataForm.routeMarkers.value;
loadPath = JSON.parse(loadStr);
when I try use this instead of getting the original coords back i get
[object Object],[object Object]
(the alerts are just to see what is going on)
Thanks for any help
When you use JSON.parse it returns the string back to its original state which is an object, all you need to do is use something along the lines of the following example.
var loadPath = JSON.parse(loadStr);
alert(loadPath.Pa); // Returns the second result of the first array
I thought that after I parsed the string back then the alert would be exactly the same as is was before being stringified, but what you said was right and has got the code working, so thanks alot.