jquery 为json格式的数据进行排序
一般得到的json格式的数据为:
var newRankList=new Array();
newRankList.put({"name":"aaa","password":"123","Id":"1"});
newRankList.put({"name":"bbb","password":"456","Id":"2"});
newRankList.put({"name":"ccc","password":"789","Id":"3"});
按照Id进行排序:
newRankList.sort(function (a,b){return a.Id-b.Id;});
操作jquery中的json数据:
数据:
var data={"status":0,
"data":{
"rw":{
"7075": {"name":"\u5c0f\u4f1f\u4ed4","vip_level":"X","union_name":"\u5929\u5730\u4f1a","level":"XX","renown":"XXXX","ticket":"0","sum_fpower":"X","trend":0,"rank":1},
"7617": {"name":"\u5b50\u6602","vip_level":"X","union_name":"\u5929\u5730\u4f1a","level":"XX","renown":"XXXX","ticket":"0","sum_fpower":"XXXXX","trend":0,"rank":2},
"923":{"name":"\u8303\u5f0f\u4e4b\u9b42","vip_level":"XX","union_name":"\u96c7\u4f63\u519b","level":"XXX","renown":"XXXX","ticket":"0","sum_fpower":"XXXX","trend":0,"rank":3}}}}
获取name的话: data.data.rw.name
如果是循环的话可以
var list=data.data.rw;
for(var i in list)
{
var name=list[i].name;
var level=list[i].level;
}