多种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‘:‘同意‘}]  

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。