开发者

json text needs to wrap in parenthesis. why?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜