程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> jquery js-jquery 處理 json 數據問題

jquery js-jquery 處理 json 數據問題

編輯:編程綜合問答
jquery 處理 json 數據問題

var json={"Table1":[{"XMID":"B0","ysdate":"2015-01-01T00:00:00","SZH":7373.0},{"XMID":"B0","ysdate":"2015-01-02T00:00:00","SZH":7845.0},{"XMID":"C0","ysdate":"2015-01-01T00:00:00","SZH":327.0},{"XMID":"C0","ysdate":"2015-01-02T00:00:00","SZH":295.0},{"XMID":"D","ysdate":"2015-01-01T00:00:00","SZH":211.0},{"XMID":"D","ysdate":"2015-01-02T00:00:00","SZH":254.0},{"XMID":"K","ysdate":"2015-01-01T00:00:00","SZH":7911.0},{"XMID":"K","ysdate":"2015-01-02T00:00:00","SZH":8394.0}]}

最終想要js輸出表格:
ysdate B0 C0 D K
2015-01-01 7373.0 327.0 211.0 7911.0
2015-01-02 7845.0 295.0 254.0 9394.0

最佳回答:


js處理就好了吧。。jquery還不一樣是js寫的,歸類下數據


    var json = { "Table1": [
    { "XMID": "B0", "ysdate": "2015-01-01T00:00:00", "SZH": 7373.0 },
    { "XMID": "B0", "ysdate": "2015-01-02T00:00:00", "SZH": 7845.0 },
    { "XMID": "C0", "ysdate": "2015-01-01T00:00:00", "SZH": 327.0 },
    { "XMID": "C0", "ysdate": "2015-01-02T00:00:00", "SZH": 295.0 },
    { "XMID": "D", "ysdate": "2015-01-01T00:00:00", "SZH": 211.0 },
    { "XMID": "D", "ysdate": "2015-01-02T00:00:00", "SZH": 254.0 },
    { "XMID": "K", "ysdate": "2015-01-01T00:00:00", "SZH": 7911.0 },
    { "XMID": "K", "ysdate": "2015-01-02T00:00:00", "SZH": 8394.0}]
    };
    var rows = json.Table1,item;
    var result = {},ritem;
    for (var i = 0, j = rows.length; i < j; i++) {
        item = rows[i];
        ritem = result[item.ysdate] || {};
        if (ritem[item.XMID]) ritem[item.XMID] += ',' + item.SZH;
        else ritem[item.XMID] = item.SZH;
        result[item.ysdate] = ritem;
    }
    var s = '<table border="1"><tr><th>ysdate</th><th>B0</th><th>C0</th><th>D</th><th>K</th></tr>';
    for (k in result) {
        s += '<tr><td>' + (k.split('T')[0]) + '</td><td>' + result[k].B0 + '</td><td>' + result[k].C0 + '</td><td>' + result[k].D + '</td><td>' + result[k].K + '</td></tr>';
    }
    s += '</table>';
    document.write(s);
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved