使用jquery $ .each解析具有多维数组值的json

Ram*_*Ram -2 javascript jquery jquery-mobile

我想使用jquery解析json值,我无法使用$ .each获取所有值但我能够获取key.i不知道如何解析这些值.以下代码用于我的project.so以下是我需要解析它的json.

{
    "0": {
        "Date": "2013-09-05 03:56:30"
    },
    "1": {
        "City": {
            "id": "1",
            "country_id": "1",
            "cityname": "Mumbai",
            "city_urlname": "mumbai",
            "lat": "19.0759837",
            "long": "72.87765590000004",
            "status": "enable",
            "flag": "0",
            "created_on": "2013-09-04 22:02:42"
        }
    },
    "2": {
        "City": {
            "id": "2",
            "country_id": "1",
            "cityname": "Chennai",
            "city_urlname": "chennai",
            "lat": "13.0524139",
            "long": "80.25082459999999",
            "status": "enable",
            "flag": "0",
            "created_on": "2013-09-04 00:53:54"
        }
    },
    "33": {
        "Category": {
            "id": "1",
            "parent_id": null,
            "name": "dream",
            "category_urlname": "culture",
            "lft": "1",
            "rght": "2",
            "created_on": "2013-08-13 05:51:04",
            "status": "enable",
            "flag": "0"
        }
    },
    "34": {
        "Category": {
            "id": "2",
            "parent_id": null,
            "name": "Education",
            "category_urlname": "education",
            "lft": "3",
            "rght": "4",
            "created_on": "2013-08-13 05:51:23",
            "status": "enable",
            "flag": "0"
        }
    },
    "35": {
        "Category": {
            "id": "3",
            "parent_id": null,
            "name": "Marketing",
            "category_urlname": "marketing",
            "lft": "5",
            "rght": "6",
            "created_on": "2013-08-13 05:51:51",
            "status": "enable",
            "flag": "0"
        }
    }
}


$.getJSON("http://demourl/something?date=0000-00-00",function(data){

                                     $.each(data, function(i,value){
                                          alert(i);
                                          alert("city"+value.City.id);-->i cannot get the city or category values
                                            });




                                     });
Run Code Online (Sandbox Code Playgroud)

The*_*pha 5

你说的不够,但如果你试试这个,你就会明白

$.each(data, function(k, v){
    if('Date' in v) console.log('Date : ' + v.Date);
    if('Category' in v) console.log('Category : ' + v.Category.name);
    if('City' in v) console.log('City : ' + v.City.cityname);
});
Run Code Online (Sandbox Code Playgroud)

检查此示例.