0

I have json result as follow:

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

How do I iterate over Records? I want impTxnId and forecastedId values.

Code:

$(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);
        });
    });
});
mishik
  • 9,973
  • 9
  • 45
  • 67
nebula
  • 3,932
  • 13
  • 53
  • 82

4 Answers4

3

Since you have jQuery tag:

$.each(data.Records, function(i, record) {
    alert(record.impTxnId + " " + record.forecastedId);
});
mishik
  • 9,973
  • 9
  • 45
  • 67
1
var records = json_result.Records;
for (var i = 0; i < records.length; i++) {
    /* do stuff with records[i].impTxnId and records[i].forcastedId */
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
0
var json = {"Result":"OK",Records:[{"impTxnId":12231,"forecastedId":26518},
    {"impTxnId":12231,"forecastedId":26519}]}

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

}
TGH
  • 38,769
  • 12
  • 102
  • 135
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);
});
sharif2008
  • 2,716
  • 3
  • 20
  • 34