0

我有这个 JSON 字符串:

[{
    "leadid": "1-2222222",
    "firstnm": "Sunil",
    "lastnm": "Bhave",
    "FLSfirstnm": "Anil",
    "FLSlastnm": "Patwardhan",
    "leadstatus": "2",
    "LGcode": "11001",
    "dtcreated": "20/03/2013",
    "ispriority": "Y"
}, {
    "leadid": "1-3333333",
    "firstnm": "Anil",
    "lastnm": "Gave",
    "FLSfirstnm": "Sooraj",
    "FLSlastnm": "Bardhan",
    "leadstatus": "1",
    "LGcode": "22001",
    "dtcreated": "20/03/2013",
    "ispriority": "N"
}, {
    "leadid": "1-4444444",
    "firstnm": "Vinod",
    "lastnm": "Sharma",
    "FLSfirstnm": "Kabir",
    "FLSlastnm": "Khan",
    "leadstatus": "2",
    "LGcode": "33001",
    "dtcreated": "20/03/2013",
    "ispriority": "Y"
}, {
    "leadid": "1-5555555",
    "firstnm": "Manish",
    "lastnm": "Joshi",
    "FLSfirstnm": "Anil",
    "FLSlastnm": "Patwardhan",
    "leadstatus": "1",
    "LGcode": "11001",
    "dtcreated": "20/03/2013",
    "ispriority": "N"
}]

我想将名字和姓氏添加为名称,从而减少元素的数量。

4

2 回答 2

2

对数组执行 for 循环,

element['name'] = element.firstnm + ' ' + element.lastnm
delete element.firstnm;
delete element.lastnm;
于 2013-04-25T05:52:13.187 回答
0

试试这个

a=[{"leadid": "1-2222222","firstnm": "Sunil","lastnm": "Bhave","FLSfirstnm": "Anil","FLSlastnm": "Patwardhan","leadstatus": "2","LGcode": "11001","dtcreated": "20/03/2013","ispriority": "Y"},
{"leadid": "1-3333333","firstnm": "Anil","lastnm": "Gave","FLSfirstnm": "Sooraj","FLSlastnm": "Bardhan","leadstatus": "1","LGcode": "22001","dtcreated": "20/03/2013","ispriority": "N"}
,{"leadid": "1-4444444","firstnm": "Vinod","lastnm": "Sharma","FLSfirstnm": "Kabir","FLSlastnm": "Khan","leadstatus": "2","LGcode": "33001","dtcreated": "20/03/2013","ispriority": "Y"},
{"leadid": "1-5555555","firstnm": "Manish","lastnm": "Joshi","FLSfirstnm": "Anil","FLSlastnm": "Patwardhan","leadstatus": "1","LGcode": "11001","dtcreated": "20/03/2013","ispriority": "N"}]
for(var i = 0; i < a.length; i++){
a[i].name = a[i].firstnm+a[i].lastnm
delete a[i]['firstnm'];
delete a[i]['lastnm'];
}
于 2013-04-25T06:09:08.753 回答