I have a simple string which is structured like this:
[[Home],[685,300],[800,380],[685,300],[Home]]
Basically its an array of co-ordinates, to create a path. The Home is used because this changes based on user's location on the map.
The problem i face is when i pass it from PHP to JS.
I json_encode the data and pass it across like this:
[{"path":"[[Home],[685,300],[800,380],[685,300],[Home]]","id":"1"}]
Then i create my object for it after i JSON.parse:
paths = {};
for(var i in data){
paths[data[i].id] = {}
paths[data[i].id].path = data[i].path;
}
The problem is data[i].path is still just a string and not a useable array. So i tried to add a secondary JSON.parse to change the string to a useable array like this:
paths[data[i].id].path = JSON.parse(data[i].path);
But this causes:
Unexpected token H
The H is obviously coming from Home that i put in the array, so I am wondering what i can do convert it to a useable array ?