Reference Original: http://www.cnblogs.com/damonlan/
Http://www.jb51.net/article/29893.htm
The role of stringify is primarily to serialize objects (converted to JSON objects)
Syntax:
Json.stringify (value [, Replacer] [, space])
1.value: Required, the objects you enter, such as arrays, classes, and so on.
2.replacer: Optional; can be an array or a method
3.space: Delimiter
Case one: (only one Parameter object)
var
student =
new
Object();
student.name =
"Lanny"
;
student.age =
"25"
;
student.location =
"China"
;
var
json = JSON.stringify(student);
alert(student);
Case two: (the first parameter array, the second parameter is an arrays, only the value of the first parameter is displayed)
var
students =
new
Array() ;
students[0] =
"Lanny"
;
students[1] =
"dong"
;
students[2] =
"I love you"
;
var
stu =
new
Array();
stu[0] =
"1"
;
stu[1] =
"2"
;
var
json = JSON.stringify(students,stu);
alert(json);
Scenario Three: (first object, second array)
var
student =
new
Object();
student.qq =
"5485891512"
;
student.name =
"Lanny"
;
student.age = 25;
var
stu =
new
Array();
stu[0] =
"qq"
;
stu[1] =
"age"
;
stu[2] =
"Hi"
;
//这个student对象里不存在。
var
json = JSON.stringify(student,stu);
alert(json);
If the value in the second array exists in the first argument, then the first value is used as the key value if it does not exist, it is not displayed, similarly, the key value in the first parameter object does not exist in the second parameter array, and does not give a display
Situation four: The second parameter exists, and is the time of the method
var
students =
new
Array() ;
students[0] =
"Lanny"
;
students[1] =
"dong"
;
students[2] =
"I love you"
;
var
json = JSON.stringify(students,switchUpper);
function
switchUpper(key, value) {
return
value.toString().toUpperCase();
}
alert(json);
The second argument simply means that each item of the first function is handled in the function.
Stringify string into JSON method