JSON.stringify用法总结:
1.JSON.stringify(args)
var person = new Object();
person.name = "ligang";
person.sex = "男";
var json = JSON.stringify(person);
//alert(json);
//alert(person);
将对象转换为JSON字符串
2.JSON.stringify(arrays,function)
var person = new Array();
person["name"] = "litianyi";
person["age"] = 18;
person["sex"] = "男";
var json = JSON.string(person,changeUpper);
function changeUpper(key,value){
return value.toString().toUpperCase();
}
alert(json);
3.JSON.stringify(arrays,secArrays);
var person = new Object();
person.name = "ligang";
person.sex = "男";
var person2 = new Array();
person2[0] = "age";
person2[1] = "sex";
person2[2] = "name";
var json = JSON.stringify(person,person2);
alert(json);
4.JSON.stringify(student,stu,10);
10:为缩进的最大值。。。