回复内容:{"body": "123", "timestamp": 1366853254, "html": "<div class=\"message\" id=\"m721cfd57-cf57-4fa9-b0a4-263151da4f7d\"><b>Scuk: <\/b>123<\/div>\n", "from": "Scuk", "id": "721cfd57-cf57-4fa9-b0a4-263151da4f7d"}
代码:
console.log( eval( '(' + response + ')'));
console.log( eval( response ));
在console.log( eval( '(' + response + ')'));
报告unexpected token
时,console.log( eval( response ));
未报告任何错误。谁能告诉我为什么?
答案 0 :(得分:6)
我们添加括号,因此它将被评估为表达式。例如,({})
被解释为对象文字,而{ ... }
被解析为块语句。
{
foo: 1,
bar: 2
}
// Uncaught SyntaxError: Unexpected token :