2

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

1
  • Obviously you are not creating proper JSON... what's the question? Commented Jul 20, 2011 at 19:18

1 Answer 1

2

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 );

Not the answer you're looking for? Browse other questions tagged or ask your own question.