开发者

JSONP Receive back non-parseable JSON

开发者 https://www.devze.com 2023-03-26 15:26 出处:网络
Receiving back Non-Parseable JSON Response. I receive back the JSON fine but it\'s in this exact format, how do I parse and say alert all containing values per row. Many thanks in advance!

Receiving back Non-Parseable JSON Response. I receive back the JSON fine but it's in this exact format, how do I parse and say alert all containing values per row. Many thanks in advance!

request start

$.ajax({
    url: apiURL+'getLocations/category/'+ category +'/countyId/'+ countyId +'/searchString/'+ searchString +'?callback=?',
    contentType: 'application/json',
    crossDomain: true,
    dataType: 'jsonp',
    callback: callTest1(),
    complete: function(data){
        if(data.code != '400')
        {
            $.each(data, function(key, value) {
                $.each(value, function(key, val){
                    alert(data.id);
                })
            });
        }
    },
    success: callTest2()
});

request end

output start

{"Location":[{"id":0,"postcodeId":85,"categoryId":0,"location":
    "Enfield Island Village"},{"id":0,"postcodeId":44,"categoryId":0,
    "location":"Isle of Dogs"},{"id":0,"postcodeId":269,"categoryId":0,
    "location":"Isleworth"},{"id":0,"开发者_运维百科postcodeId":135,"categoryId":0,
    "location":"Islington"}]
}

output end


Try this.

var data = {"Location":[{"id":0,"postcodeId":85,"categoryId":0,"location":
    "Enfield Island Village"},{"id":0,"postcodeId":44,"categoryId":0,
    "location":"Isle of Dogs"},{"id":0,"postcodeId":269,"categoryId":0,
    "location":"Isleworth"},{"id":0,"postcodeId":135,"categoryId":0,
    "location":"Islington"}]
};

$.each(data.Location, function(index, val){
    alert(val.id + " , " + val.postcodeId + " , " +val.categoryId + " , " +val.location );
});

I think that you are missing the .Location part.

If you are not comfortable with hard coded values, try this.

$.each(data.Location, function(index, datum) {
    $.each(datum, function(key, value) {
        alert(key + " : " + value.toString());
    });
});

Working Demo: http://jsfiddle.net/naveen/kLEA6/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号