JavaScript的Eval与JSON.parse的区别

json的定义以及用法:

  JSON(JavaScript Object Notation)是一种轻量级的数据格式,采用完全独立于语言的文本格式,是理想的数据交换格式。同时,JSON是Javascript原生格式,这意味着在javascript中处理JSON数据不需要任何特殊的API或工具包,而且效率非常高。

基本格式:varjsonData='{"data1":"Hello,","data2":"world!"}'

很多json数据存入数组

{"name":"LiLei","age":19,"sex":"male"},{"name":"HanMei","age":18,"sex":"famale"}]

总体而言,json是相对比较容易的理解和使用的,但同时存在很多的陷阱,如果不注意的话很容易掉进去。

json与eval对比:

  json格式非常受欢迎,而解析json的方式通常用JSON.parse()但是eval()方法也可以解析,这两者之间有什么区别呢?

JSON.parse()之可以解析json格式的数据,并且会对要解析的字符串进行格式检查,如果格式不正确则不进行解析,而eval()则可以解析任何字符串,eval是不安全的。

例如下面代码:

function EvalTest() {

    var content = "console.log('javascript')";
eval(content); } function JSONTest() {
var content ="console.log('jvascript')";
JSON.parse(content); }

它们的执行结果为:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtUAAACaCAIAAADpQCOsAAAgAElEQVR4nO3da1AUZ74/cN+kyjepyqk6lVNlJakK/w1FcurU4ezJWsnRYzZsNsT1hKxBYzYEQkI2QpSRRCUqojAiiIZ1lctojEhAg47iDUTElWhWdAREuYnMDMxwH5wbA8MwbTP9+7/oSdPOBUbEQc33U78XONP3Jukvz/N096yioiICAAAA8KNZyB8AAADgZ8gfAAAA4G/IHwAAAOBvyB8AAADgb8gf4CeMTqdJk44NDU08mb27q+G9RZYr1f7ZKm/GrNbbccv7CwumZWnGynMDh4uJ46ZlaQAAT4DJ84fFYrl69ap/tuZh02g027Zts9lsU5i3tLT0xIkT07UluoOFbV/GDt+8cfNPoTZl23QtdmKWK9WX5zx7ec6zuuJD9zuvrvgQP+/UksGY1apa8/Xgz5dcltn2ZazDNiL+8PHKH6MdHZq0VJddYI2Gm4veEe+C++7f1d+5+c4fLVeqNWlSTZp0WrcdAOAxMHn+qK+vz87OPnfun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fWWs1V89mzn3ZXewgEfAiYYfyoehxEcTAcPjg9E/f57+vjj8ftifFyF+17woxr55oGmJnrzTaqu9jr+w5f8IXTxeGwBcqlJ84d4F155xTlwxD1/mM2kVNLSpTR79vgpu3KF3nrL2dhz+DAtWULd3ZSdPX48hWEo7vOafxlYKnRweDtl5eUUHHzPgaqpoddfp2eeobQ0+vjjifKHXk/p6c5fM2HekBB66qnxnRWChV5PiYkkkVBfH3V3k0TinJHfEt/zh/vvttlMZvM/Tp/en5fHt2oY2ttTk5M1jY1C/hBujbF0dW3bsgX3v6BQqMe9nrjnrx89Sh984Gy3VyjojTfGh4JOY/X00NdfU2XlzO/vY1dT7gl60gvP/0ChUL+qeuLyB9+Fz/8lHRw8fjPnNFZCAj33HOXnT/+Sfw2F/OG9DO3teX//O55/ikKhnvg6sGfPE5c/UCgUCoVCPfKF/IFCoVAoFMrfNauoqIhu30ahUCgUCoXyW80qKioiAAAAAD9C/gAAAAB/Q/4AAAAAf5vO/BEQEDBdiwIAAIAnGPIHAAAA+BvyBwAAAPjb5Pmjz+yQnbdz3OTLQv4AAAAAX0yePw5eZuZutCTLbWOOSZaF/AEAAAC+8Kn/5Yef7XM3Wr4qGrHfnWgy5A8AAADwha/jP07UMq8lW77YZ7XavfbEIH8AAACAL5A/AAAAwN/Q/wIAAAD+hvGnAAAA4G+4/xYAAAD8Dc8fAwAAAH9D/gAAAAB/Q/4AAAAAf5vO/AEAAADgC+QPAAAA8DfkDwAAAPA35A8AAADwN+QPAAAA8DfkDwAAAPA35A8AAADwN+QPAAAA8DfkDwAAAPA35A8AAADwN+QPAAAA8DfkDwAAAPA35A8AAADwN+QPAAAA8Lf/DxilPTA6Ppt3AAAAAElFTkSuQmCC" alt="" />

  用eval可以解析,并且会在控制台中输入出需要打印的字符串,而用JSON.parse()则解析不了。eval在解析字符串时,会执行该字符串中的代码, 其实console.log并没有什么坏处,可怕的是如果用恶意用户在json字符串中注入了向页面插入木马链接的脚本,用eval也是可以操作的,而用JSON.parse()则不必担心这个问题。

JavaScript的Eval与JSON.parse的区别的更多相关文章

  1. eval()和JSON.parse()的区别

    我们将一个josn字符串解析为对象的时可以使用两种方法: 假设有一个json字符串: '{ "student" : [ {}, {}, {} ] }' 然后解析为对象: 1.eva ...

  2. eval、json.parse()的介绍和使用注意点

    原文:eval.json.parse()的介绍和使用注意点 eval和json.parse的使用 eval:来源于官网 定义和用法 eval() 函数可计算某个字符串,并执行其中的的 JavaScri ...

  3. json.stringify()的妙用,json.stringify()与json.parse()的区别

    一.JSON.stringify()与JSON.parse()的区别 最近做项目,发现JSON.stringify()使用场景真的挺多,我们都知道JSON.stringify()的作用是将 JavaS ...

  4. 解析JSON的两种方法eval()和JSON.parse()

    解析JSON 一种方法是使用eval函数. var dataObj = eval("("+json+")"); 必须把文本包围在括号中,这样才能避免语法错误,迫 ...

  5. 【javascript基础】 原生JSON.parse解析异常问题

    [问题背景]用jQ,ajax返回json,返回的字符串如:{name:"suntiger035"},status:200,readyState:4,代码无任何问题,结果,succe ...

  6. JSON.stringify()和JSON.parse()的区别

    JSON.stringify()此方法用于将一个对象解析成字符串并返回. JSON.parse()此方法刚好相反是将一个字符串对象解析成一个JSON对象.

  7. python中eval()和json.loads的区别

    一.最近在写接口测试脚本时,发现当读取Excel用例时,有时候要用eval,有时候又要用json.loads,不知道区别,只能换一下就可以用了,不知道其中的原理,特地百度了下.于是就记录了下,以便后续 ...

  8. JSON.parse()和eval()的区别

    json格式非常受欢迎,而解析json的方式通常用JSON.parse()但是eval()方法也可以解析,这两者之间有什么区别呢? JSON.parse()之可以解析json格式的数据,并且会对要解析 ...

  9. JSON.parse与eval区别

    两种方式都可以解析json字符串,不过有时候JSON.parse解析会失败,失败原因有多种,下面会指出一种. JSON.parse()解析json格式的数据,会对要解析的字符串进行格式检查,如果格式不 ...

随机推荐

  1. JQuery学习笔记——JQuery基础

    #,JQuery避免名称冲突的方法 var jq = jQuery.noConfilct(); jq.ready( function(){     jq("p").hidden() ...

  2. LeetCode-Count Univalue Subtrees

    Given a binary tree, count the number of uni-value subtrees. A Uni-value subtree means all nodes of ...

  3. iOS——浅谈iOS中三种生成随机数方法

    ios 有如下三种随机数方法:

  4. sublime文档

    英文http://docs.sublimetext.info/en/latest/index.html 翻译http://feliving.github.io/Sublime-Text-3-Docum ...

  5. 成都普华永道税务开发的offer

    首先这是一个.net税务开发的offer,我是做开发的. 有没有人在成都普华永道的,最近收到普华永道的offer,如果有的话请联系我.想知道里面的情况.最想知道里面的加班情况,薪资还是有点诱惑的.毕竟 ...

  6. 判断一个点是否在多边形内部,射线法思路,C#实现

    感谢原作者,原理请看原作者的文章 http://www.html-js.com/article/1517 C#实现 public string rayCasting(PointF p, PointF[ ...

  7. 大型网站系统架构实践(六)深入探讨web应用集群Session保持

    原理 在第三,四篇文章中讲到了会话保持的问题,而且还遗留了一个问题,就是会话保持存在单点故障, 当时的方案是cookie插入后缀,即haproxy指负责分发请求,应用服务自行保持用户会话,如果应 用服 ...

  8. 【Moqui业务逻辑翻译系列】Sales Representative Seeks Prospects and Opportunities 销售代表寻找期望合作对象和机会

    h1. Sales Representative Seeks Prospects and Opportunities 销售代表寻找期望合作对象和合作机会 h4. Ideas to incorporat ...

  9. words in view Moqui resource code

    annotation:注释 注解 documentation:文件  证明文件 embed:嵌入 context:环境  上下文 explicity: 明确的 明白的 conversion: 转化

  10. Android EditText使用详解

    一:新建HelloEditText工程 新建一个Hello world详细步骤可以参见 Android教程之三:第一个Android应用,HelloWorld 创建设置如下: Project name ...