json数组怎么解析?
vararr=[{"date":"04","fee":"100"},{"date":"05","fee":"50"},{"date":"06","fee":"200"},...
var arr=[{"date":"04","fee":"100"},{"date":"05","fee":"50"},{"date":"06","fee":"200"},{"date":"07","fee":"1000"},{"date":"08","fee":"500"},{"date":"09","fee":"637.41"}];
怎么把上面的json数据解析.解析结果是fee中存的最大值放在第一位,也就是倒序排列,并且倒序之后要求date能够和fee匹配,
结果:{date:07,fee:1000},{date:09,fee:637.41},{date:08,fee:500},{date:06,fee:200},{date:04,fee:100},{date:05,fee:50} 展开
怎么把上面的json数据解析.解析结果是fee中存的最大值放在第一位,也就是倒序排列,并且倒序之后要求date能够和fee匹配,
结果:{date:07,fee:1000},{date:09,fee:637.41},{date:08,fee:500},{date:06,fee:200},{date:04,fee:100},{date:05,fee:50} 展开
1个回答
推荐于2016-11-15
展开全部
function getSort() {
var maxFee = 0;
var temObj;
var n;
if (arr.length > 0) {
for (var i = 0; i < arr.length; i++) {
var obj = arr[i];
if (obj.fee - maxFee > 0) {
maxFee = obj.fee;
temObj = obj;
n = i;
}
}
newArr.push(temObj);
arr.splice(n,1);
getSort();
}
}
var arr=[{"date":"04","fee":"100"},{"date":"05","fee":"50"},{"date":"06","fee":"200"},{"date":"07","fee":"1000"},{"date":"08","fee":"500"},{"date":"09","fee":"637.41"}];
var newArr=[];
getSort();
for (var i = 0; i < newArr.length; i++) {
alert(newArr[i].fee + " " + newArr[i].date)
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询