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}
展开
 我来答
匿名用户
推荐于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)
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式