javascript 对象转换成json串

方法一:

var josn = new Object();  
json.id = "007";
json.name = "zhangsan"; 
json.sex = "男"; 
输出为:
{name:"zhangsan",value:"123",id:"007",sex:"男"}

 方法二:

var json = {};
json["id"] = "007"; 
json["name"] = "zhangsan"; 
json["sex"] = "男"; 
输出结果:
   {name:"zhangsan",value:"123",id:"007",sex:"男"}

 方法三:

var json = {
    "id":"007",
    "name":"zhangsan",
     "sex":"男"
};
输出结果:
   {name:"zhangsan",value:"123",id:"007",sex:"男"}

 PS:

JSON.stringify(json)  
输出为:  
{"name":"zhangsan","value":"123","id":"007","sex":"男"}

 

你可能感兴趣的:(JavaScript)