Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

parsin json fails

Participant ,
Sep 07, 2012 Sep 07, 2012

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?

TOPICS
Scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 07, 2012 Sep 07, 2012

Just for fun, try this:

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

Dan

Translate
Community Expert ,
Sep 07, 2012 Sep 07, 2012

Just for fun, try this:

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

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 08, 2012 Sep 08, 2012

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


Mike Cardeiro

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2012 Sep 08, 2012
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines