首页 > 代码库 > 从list表单序列化后的值转成标准json

从list表单序列化后的值转成标准json

                    var json = {"name":["1111","222"],"sex":["男","女"],"age":["1111","2222"],"uNo":["111","2222"]};//从list表单序列化取出来的格式
     
var param = []; //定义数组 for(var i = 0; i < json.name.length;i++) {//这里的length有bug,回头再改 name= json.name[i]; sex = json.sex[i]; age = json.age[i]; uNo = json.uNo[i]; param.push({name:name,sex:sex,age:age,uNo:uNo});//追加到数组中 } var data = http://www.mamicode.com/JSON.stringify(param,null,4); alert(data);

转后的格式

[
    {
        "name": "1111",
        "sex": "男",
        "age": "1111",
        "uNo": "111"
    },
    {
        "name": "222",
        "sex": "女",
        "age": "2222",
        "uNo": "2222"
    }
]

拼接成后台想要的json

var data2 = "{"+‘"data"‘+":"+ data+"}";
alert(data2);

 

从list表单序列化后的值转成标准json