The difference between json.parse () and eval () parsing JSON in JavaScript

Source: Internet
Author: User

varjsonData=‘{"data1":"Hello,","data2":"world!"}‘

Call Method Jsondata.data1,jsondata.data2

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

Call Method Jsondata[0].name,jsondata[1].sex

evalJson=eval(‘(‘+jsonData+‘)‘);

varjsonParseJson=JSON.parse(jsonData);

Using the Eval function to parse JSON is a very insecure way to use it without the best possible reason that eval not only resolves the JSON string, but also executes the block of code in it (if any).

So what we used to do is use the Json.parse () method to parse
var obj = json.parse (jsondata);

The difference between json.parse () and eval () parsing JSON in JavaScript

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.