Eval question in javascript
Thank you. here is the correct question:
{
"VID":"60",
"name":"\u4f1a\u9634",
"requireLevel":"20",
"levelMax":"5",
"venationRequirement":"0",
"description":"\u6c14\u6d77\u4e0a\u9650\u63d0\u9ad8[Affect1]\u70b9",
"cost":{"1":"240","2":"360","3":"400","4":"600","5":"720"},
"difficult":{"1":"1024","2":"973","3":"921","4":"870","5":"819"},
"affect":{"1":"200","2":"500","3":"900","4":"1400","5":"2000"},
"descriptions":{
"1":"\u6c14\u6d77\u4e0a\u9650\u63d0\u9ad8200\u70b9",
"2":"\u6c14\u6d77\u4e0a\u9650\u63d0\u9ad8500\u70b9",
"3":"\u6c14\u6d77\u4e0a\u9650\u63d0\u9ad8900\u70b9",
"4":"\u6c14\u6d77\u4e0a\u9650\u63d0\u9ad81400\u70b9",
"5":"\u6c14\u6d77\u4e0a\u9650\u63d0\u9ad82000\u70b9"
}
}
I have used json_encode () in php and ajax request to get the response body.
but when i use eval () to parse the response text. it is not right.
moonshadow and james gregory have answered this question in the comments below. Again.
+1
IvanLi
source
to share
5 answers
Javascript is a little confused about what context it parses in. Prepare '(' and add ')' before passing the string to eval () to make it parse the whole thing as an expression.
(Your asked question is also missing labels for the outer associative array as others have pointed out, however the data samples you provided clarify the actual problem.)
+3
source to share