jquery:迭代json结果

时间:2013-06-11 04:00:11

标签: jquery ajax json

我的json结果如下:

{"Result":"OK","Records":[{"impTxnId":12231,"forecastedId":26518},
{"impTxnId":12231,"forecastedId":26519}]}

如何迭代记录?我想要impTxnIdforecastedId值。

代码:

$(function(){
    var request = $.ajax({
        url: '<%=getMatchedTransactionsURL%>',
        type : "post",
    });
    request.done(function (data) {
        alert(data); // This displays the data. 
        $.each(data.Records, function(i, record) {
            alert(record.impTxnId + " " + record.forecastedId);
        });
    });
});

4 个答案:

答案 0 :(得分:3)

因为你有jQuery标签:

$.each(data.Records, function(i, record) {
    alert(record.impTxnId + " " + record.forecastedId);
});

答案 1 :(得分:1)

var records = json_result.Records;
for (var i = 0; i < records.length; i++) {
    /* do stuff with records[i].impTxnId and records[i].forcastedId */
}

答案 2 :(得分:0)

var json = {"Result":"OK",Records:[{"impTxnId":12231,"forecastedId":26518},
    {"impTxnId":12231,"forecastedId":26519}]}

for(var i = 0; i < json.Records.length;i++){

}

答案 3 :(得分:0)

var j='{"Result":"OK","Records":[{"impTxnId":12231,"forecastedId":26518},'+
      '{"impTxnId":12231,"forecastedId":26519}]}';


var a=JSON.parse(j);
   $.each(a.Records, function(i, record) {
   alert(record.impTxnId + " " + record.forecastedId);
});