4 回答
TA贡献1821条经验 获得超5个赞
如果使用,您将更容易受到攻击eval:JSON是Javascript的子集,而json.parse仅解析JSON,而eval这却为所有JS表达式敞开了大门。
TA贡献1784条经验 获得超8个赞
所有JSON.parse实现最有可能使用eval()
JSON.parse基于Douglas Crockford的解决方案,该解决方案eval()在497行使用。
// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.
j = eval('(' + text + ')');
的优点JSON.parse是它可以验证参数是否为正确的JSON语法。
TA贡献1942条经验 获得超3个赞
JSON.parse()和eval()接受的内容有所不同。尝试评估:
var x =“ {\” shoppingCartName \“:\” shopping_cart:2000 \“}”
eval(x) //won't work
JSON.parse(x) //does work
添加回答
举报
