开发者

json text needs to wrap in parenthesis. why?

开发者 https://www.devze.com 2023-03-17 19:49 出处:网络
if you look at http://www.json.org/js.html you wi开发者_高级运维ll find a line that states: The text must be wrapped in parens to

if you look at http://www.json.org/js.html you wi开发者_高级运维ll find a line that states:

The text must be wrapped in parens to avoid tripping on an ambiguity in JavaScript's syntax.

var myObject = eval('(' + myJSONtext + ')');

can some body explain what this ambiguity is ???

Many thanks


From here: http://rayfd.wordpress.com/2007/03/28/why-wont-eval-eval-my-json-or-json-object-object-literal/

"Note that an ExpressionStatement cannot start with an opening curly brace because that might make it ambiguous with a Block"

0

精彩评论

暂无评论...
验证码 换一张
取 消