Phani Kumar

Phani Kumar

  • NA
  • 162
  • 24.8k

How to convert JSON response list to array in jquery

Sep 10 2018 7:01 AM
Hi,
 
To whom so ever it may concern,
 
I am using API to fetch the data into my form using jquery, I am getting response as list in below mentioned way
 
  1. list:Array(1)
    1. 0:
      1. due:null
      2. originalAmount:463872
      3. outstandingAmount:463872
      4. taxperiod:
        1. from:"2017-01-01"
        2. to:"2017-02-01"
      5. type:"VAT Return Debit Charge"
while I am trying to fetch this list in below mentioned way
 
success(function (data) {
debugger;
if (data != null) {
if (data.status == 'Ok') {
//var xmlDoc = $.parseXML(data.d);
//var xml = $(xmlDoc);
//var customers = xml.find("Table");
//var rows = '';
for (var i = 0; i < data.list.length > 0; i++) {
debugger;
$scope.due = data.list[i].due == null ? '' : data.list[i].due;
$scope.originalAmount = data.list[i].originalAmount == null ? 0.00 : data.list[i].originalAmount;
$scope.outstandingAmount = data.list[i].outstandingAmount == null ? 0.00 : data.list[i].outstandingAmount;
$scope.paidAmount = (Number(data.list[i].originalAmount) - Number(data.list[i].outstandingAmount)) == null ? 0.00 : Number(data.list[i].originalAmount) - Number(data.list[i].outstandingAmount);
$scope.formtype = data.list[i].type == null ? '' : data.list[i].type;
}
}
}
 
 but unable to get inside the for loop
 
here it may increase the count. I want to bind this data to html table, can anyone explain me how to acheive this, by this my project got stuck up, basing on this I need to pass the data to next page. This has to be done in jquery only
 
Thanks for the help in advance 

Answers (3)