日期:2014-05-17  浏览次数:20693 次

js处理JSON数据去重(大婶快来)

{                                                      
"total":3,                                                      
"rows":[                                                          
{"code":"001","name":"北京市","qymc":"雪花啤酒","pfkmc":"雪花排气口1#"},         
{"code":"002","name":"北京市","qymc":"雪花啤酒","pfkmc":"雪花排气口2#"},         
{"code":"003","name":"上海市","qymc":"雪花啤酒","pfkmc":"雪花排气口2#"}
]                                                          
}   


需求:name重复的json 只留一条,就是如果name相同就去重
------解决方案--------------------
	var $a ={                                                      
    "total":3,                                                      
    "rows":[                                                          
        {"code":"001","name":"北京市","qymc":"雪花啤酒","pfkmc":"雪花排气口1#"},         
        {"code":"002","name":"北京市","qymc":"雪花啤酒","pfkmc":"雪花排气口2#"},         
        {"code":"003","name":"上海市","qymc":"雪花啤酒","pfkmc":"雪花排气口2#"}
    ]                                                          
}

$b = {"total":0,"rows":[]};
var tem = $a.rows;
var