我有这个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"
}]
我希望将名字和姓氏添加为名称,从而减少元素数量。
答案 0 :(得分:2)
在数组上执行for循环,
element['name'] = element.firstnm + ' ' + element.lastnm
delete element.firstnm;
delete element.lastnm;
答案 1 :(得分: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'];
}