Fork me on GitHub
.net求学者

多种JSON格式及遍历方式

 /*数组*/
        var arr = [["name", "value"], ["name1", "value1"]];
        var item;
        for (item in arr) {
            alert("Name: " + item[0] + ", Value: " + item[1]);
        }

        $.each(arr, function (i, n) {
            alert("Name: " + n[0] + ", Value: " + n[1]);
        });



        /*JSON*/
        $.each({ "长沙": "CHHN000000", "宁乡": "CHHN000100" }
, function (i, n) {
    alert("Name: " + i + ", Value: " + n);
});


        //"{Table1: [{}],Table2: [{}],Table3: [{{&table3Item&}}]}";
        var results = { Table1: [{ "name": '数据name', "type": '数据type'}], Table2: [{ "id": '数据id', "gx": '数据gx', "val": '数据val'}] }

        for (var i in results.Table1[0]) {
            try {
                $("#" + i).val(results.Table1[0][i]);
            }
            catch (ex) {
            }
        }




        var results = { "Tables": [{ "Rows": [["1", "1t"], ["2", "2t"]]}] }
        result = eval("(" + result + ")");
        if (result.Tables[0].Rows.length > 0) {
            for (var k = 0; k < result.Tables[0].Rows.length; k++) {
                result.Tables[0].Rows[k][0];
                result.Tables[0].Rows[k][1];
            }

        };



        var cityAll = { "Items": [["长沙", "CHHN000000"], ["宁乡", "CHHN000100"]] };
        alert(cityAll.Items[0][1])
{"Item":[["12","21"]]}
{"Rows":[["11","22"]]}  

{"Item":[["12","21",{"Rows":[["11","22"]]} ]]}

输出:
    for(var i=0;i<result.Item.length; i++) {
            for (var j = 0; j < result.Item[i][3].Rows.length; j++)
    }


[{'UserID':'5d9ad5dc1c5e494db1d1b4d8d79b60a7','UserName':'姓名','UserSystemName':'2234','OperationName':'负责人','OperationValue':'同意'}, {'UserID':'2c96c3943826ea93013826eafe6d0089','UserName':'姓名','UserSystemName':'1234','OperationName':'负责人','OperationValue':'同意'}]  

 

//for in 遍历
{
    "Z05": {
        "/Date(1494970200000+0800)/": [
            0.0102
        ],
        "/Date(1494404400000+0800)/": [
            0.7782
        ]
    },
    "Z14": {
        "/Date(1494418800000+0800)/": [
            3.1585
        ],
        "/Date(1494404400000+0800)/": [
            5.991
        ]
    },
    "Z17": {
        "/Date(1494418800000+0800)/": [
            0.0815
        ]
    }
}

 

posted @ 2015-03-27 18:21  hy31337  阅读(879)  评论(0编辑  收藏  举报
.net求学者