Why the open quote and bracket for eval('(' + jsonString+ ')') when parsing json string

后端 未结 3 1987
梦谈多话
梦谈多话 2020-11-27 21:02

Can you please tell me the reason for this specific syntax structure

 eval(\'(\' + jsonString+ \')\')

When parsing json text. Crockford sa

3条回答
  •  清酒与你
    2020-11-27 21:39

    @el.pescado, the string after executed by eval should be javascript understandable. i.e if you are assigning the above string to the varible as follows

    eval(' var foo1 = {"foo" : "bar"}'); foo1.foo will return bar

    so, my assumption is, as there is no statement like that starts with "{" in javascript, it is throwing the error.

提交回复
热议问题