为什么eval在这里失败? [英] Why eval fails here?
本文介绍了为什么eval在这里失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
0001: response
$[0] = [string] "{\"code\":200,\"id\":121}"
0001: eval(response)
SyntaxError: invalid label
有谁知道?
推荐答案
您必须将其包装在()
中以触发表达式评估,像这样:
You have to wrap it in ()
to trigger expression evaluation, like this:
eval("(" + response + ")")
虽然更好的方法是原生JSON处理:
Though a better method is native JSON handling:
var result = JSON.parse(response);
只需包含 json2.js ,调用是相同的...它只是添加全局 JSON
对象,如果它丢失了。
Just include json2.js for older browser (< IE8) support, the call is the same...it just adds the global JSON
object if it's missing.
这篇关于为什么eval在这里失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文