Skip to main content
Inspiring
September 8, 2012
Answered

parsin json fails

  • September 8, 2012
  • 1 reply
  • 1093 views

I am opening a socket ant getting a doc with json over the net.  heres a code snipet.

response=  conn.read();
lines= response.split(/\n/);
var j= lines[lines.length-1];
conn.close();
j = eval(j);

(why the hell I cant paste into here without it becoming a table I'll never know)

if I chane the last line to alert(j) it shows me the correct json string.  When I do eval(j) I get the message "unable to execute script at line 1 ; expected

am I missing something here?

This topic has been closed for replies.
Correct answer Dan Ebberts

Just for fun, try this:

eval("(" + j + ")");

Dan

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
September 8, 2012

Just for fun, try this:

eval("(" + j + ")");

Dan

Inspiring
September 8, 2012

holy sh*t, I can't beleive that actually works...can you explain why (just curious)


Mike Cardeiro

Dan Ebberts
Community Expert
Community Expert
September 8, 2012

Just Google "javascript eval json". I think the best answer is the one from stackoverflow (fourth from the top). Read the top few responses.

Dan