循环jQuery ajax成功的JSON响应

How can I loop through the JSON-type response?

In my ajax_request.php

$json = '{

    "gallery": {
    "galleryName": "Gallery Name 1",
    "artist": "Artist 1",
    "description": "Description 1",
    "photos": {
        "photo" : {
            "location" : "location 1",
             "name"    : "name 1"

        } ,
        "photo" : {
            "location" : "location 1.2",
             "name"    : "name 1.2"

        }, 
        "photo" : {
            "location" : "location 1.3",
             "name"    : "name 1.3"

        }
    }
},

"gallery": {
    "galleryName": "Gallery Name 2",
    "artist": "Artist 2",
    "description": "Description 2",
    "photos": {
        "photo" : {
            "location" : "location 2.1",
             "name"    : "name 2.1"

        } ,
        "photo" : {
            "location" : "location 2.2",
             "name"    : "name 2.2"

        }, 
        "photo" : {
            "location" : "location 2.3",
             "name"    : "name 2.3"

        }
    }
}';
 echo json_encode($json);

In my index.php

$.ajax({
    url: "ajax_request.php",
    dataType:"json", 
    type: "POST",
    success: function(data){
        //code here to loop
});

Please help. Thanks.

Since you are using jQuery you can use the jquery each function to loop trough json

$.ajax({ url: "ajax_request.php", dataType:"json", type: "POST", success: function(data){
    $.each(data, function(key, value) {
       /// do stuff with key and value
    });
   }); 
});