0

我的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

4 回答 4

3

因为你有 jQuery 标签:

$.each(data.Records, function(i, record) {
    alert(record.impTxnId + " " + record.forecastedId);
});
于 2013-06-11T04:01:33.323 回答
1
var records = json_result.Records;
for (var i = 0; i < records.length; i++) {
    /* do stuff with records[i].impTxnId and records[i].forcastedId */
}
于 2013-06-11T04:01:58.813 回答
0
var json = {"Result":"OK",Records:[{"impTxnId":12231,"forecastedId":26518},
    {"impTxnId":12231,"forecastedId":26519}]}

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

}
于 2013-06-11T04:02:15.483 回答
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);
});
于 2013-06-11T04:11:36.270 回答