JSON. stringify syntax, json. stringify

Source: Internet
Author: User

JSON. stringify syntax, json. stringify

Purpose: this function is mainly used to serialize objects.
Some people may be allergic to serialization. My understanding is simple. That is to say, convert the original object type to the string type (or, more specifically, the json type ). That's simple. For example, if you have a class, you can use this method to convert it to the corresponding json type. It's easy.
Next, let's take a look.
Syntax:
JSON. stringify (value [, replacer] [, space])
Value: A required field. It is the object you enter, such as arrays and classes.
Replacer: This is optional. It can be divided into two methods: method and array.
Start to use instance description;

<script type="text/JavaScript" src="./js/customization/json2.js"></script>
<script language="javascript">        var t = JSON.parse('{"name":123}');        alert(t.name);             var student = new Object();   student.name = "Lanny";   student.age = "25";   student.location = "China";var ar = new Array();for(var i = 0 ;i<8;i++){  var elelem = new Object();  elelem.name = 'aa'+i;  elelem.age = 'bb'+i;  ar.push(elelem);}  student.par = ar; var json = JSON.stringify(student);   alert(student);   alert(json);  </script>

 


 

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.