Reputation: 2071
I am doing a ajax post and getting this date back from the server (I have control of the server if I need to make changes):
"[{4e2384d1eca4a61030d8746c:'27.7766405735821,-81.9141438476562,stuff,'},{4e237b32eca4a6103061abf7:'27.94904038727,-82.6213887207031,test again,'}]"
I am trying to convert it to a map ie
{4e2384d1eca4a61030d8746c:'27.7766405735821,-81.9141438476562,stuff,'}
{4e237b32eca4a6103061abf7:'27.94904038727,-82.6213887207031,test again,'}
in Firebug where I receive the data I am doing a watch of
$.parseJSON(txt) //where txt is the data received
but I get an error
Invalid JSON:
[{4e2384d1eca4a61030d8746c:'27.7766405735821,-81.9141438476562,stuff,'},{4e237b32eca4a6103061abf7:'27.94904038727,-82.6213887207031,test again,'}]
TIA
Upvotes: 2
Views: 3124
Reputation: 322592
If you can't make it valid JSON by using double quotes around the keys and string values:
'[{"4e2384d1eca4a61030d8746c":"27.7766405735821,-81.9141438476562,stuff,"},{"4e237b32eca4a6103061abf7":"27.94904038727,-82.6213887207031,test again,"}]'
...then you may be stuck with eval()
, but you should only use it if you're absolutely certain the data is secure.
var result;
eval( 'result=' + txt );
Upvotes: 2