JSON.parse与eval() [英] JSON.parse vs. eval()
本文介绍了JSON.parse与eval()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
My Spider Sense警告我,使用 eval()
来解析传入的JSON是一个坏主意。我只是想知道 JSON.parse()
- 我认为它是JavaScript的一部分而不是浏览器特定的功能 - 更安全。
My Spider Sense warns me that using eval()
to parse incoming JSON is a bad idea. I'm just wondering if JSON.parse()
- which I assume is a part of JavaScript and not a browser-specific function - is more secure.
推荐答案
如果使用 eval
,您更容易受到攻击: JSON是Javascript的一个子集,json.parse只解析JSON,而 eval
将为所有JS表达式打开大门。
You are more vulnerable to attacks if using eval
: JSON is a subset of Javascript and json.parse just parses JSON whereas eval
would leave the door open to all JS expressions.
这篇关于JSON.parse与eval()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文