Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to parse json string using java script eval function

I am facing issue with the following Json reponse object in the javascript eval function;Getting java script error expected } because of special characters Tamás and Török

{
  [{
    "userFirstNm": "Naresh",
    "userAsscId": "70336",
    "userLastNm": "Yashwantrao",
    "userLanId": "a70336"
  }, {
    "userFirstNm": "Tamás",
    "userAsscId": "37732",
    "userLastNm": "Török",
    "userLanId": "a37732"
  }]
}

Is there is any solution to resolve this problem.

alt text alt text

like image 432
Vicky Avatar asked Oct 25 '22 12:10

Vicky


1 Answers

Ah I know what the problem is. You need to wrap the object expression in parentheses for eval to work correctly.

alert(eval("({\"userFirstNm\":\"Tamás\",\"userAsscId\":\"37732\",\"userLastNm\":\"Török\",\"userLanId\":\"a37732\"})"));
like image 193
ChaosPandion Avatar answered Nov 15 '22 12:11

ChaosPandion