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>