js字符串转JSON
第一种方式:
使用js函数eval();
testJson=eval(testJson);是错误的转换方式。
正确的转换方式需要加(): testJson = eval("(" + testJson + ")");
eval()的速度非常快,但是他可以编译以及执行任何javaScript程序,所以会存在安全问题。在使用eval()。来源必须是值得信赖的。需要使用更安全的json解析器。在服务器不严格的编码在json或者如果不严格验证的输入,就有可能提供无效的json或者载有危险的脚本,在eval()中执行脚本,释放恶意代码。
js代码:
<div class="dp-highlighter bg_javascript" style="font-family: Consolas, 'Courier New', Courier, mono, serif; background-color: #e7e5dc; width: 687px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"> view plaincopy<div style="width: 18px; height: 18px;">
页:
[1]