CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2016
    Posts
    6

    How to iterate the Json object for a web service call?

    Below is my payload for a given WebService in JSON format:

    {
    "SupplierPOList": {
    "RowCount": 1,
    "SupplierPOListDetails": {
    "SupplierPOHeader": [
    {
    "VendorSetid": "STATE",
    "VendorId": "0000099475",
    "POBusinessUnit": "DRC01",
    "POId": "0000128530",
    "PODate": "2014-01-13",
    "ActivityDate": "2014-02-25",
    "EnteredDate": "2014-01-13",
    "DispatchDateTime": "2014-01-16T11:10:45.000000-05:00",
    "DueDate": "2014-01-13",
    "POAmount": 460.63,
    "Buyer": "eSettlements Buyer User",
    "PaymentTerms": "Net 30",
    "CurrencyCd": "USD",
    "OnHold": "No",
    "POStatus": "Complete",
    "POAckStatus": "Not Required",
    "RecvStatus": "PO Not Received",
    "SupplierPOLineList": {...},
    "SupplierInvoiceList": {
    "POBusinessUnit": "DRC01",
    "POId": "0000128530",
    "SupplierInvoiceHeader": [
    {
    "InvoiceDate": "2014-01-27",
    "InvoiceId": "6942150",
    "EnteredDate": "2014-02-03",
    "InvoiceAmount": 460.63,
    "APBusinessUnit": "DRC01",
    "VoucherId": "00791073",
    "DueDate": "2014-02-26",
    "CurrencyCd": "USD",
    "PaymentTerms": "Net 30",
    "SupplierPaymentList": {
    "APBusinessUnit": "DRC01",
    "VoucherId": "00791073",
    "SupplierPaymentHeader": [
    {
    "PaymentDate": "2014-02-26",
    "PaymentId": "0007275500",
    "PaymentIdRef": "0003501364",
    "InvoiceId": "6942150",
    "InvoiceDate": "2014-01-27",
    "PaymentAmount": 460.63,
    "CurrencyCd": "USD",
    "PaymentMethod": "Electronic Funds Transfer",
    "Name1": "HAZELDEN",
    "Name2": null,
    "Country": "USA",
    "Address1": "PO BOX 176",
    "Address2": null,
    "Address3": null,
    "Address4": null,
    "City": "CENTER CITY",
    "State": "MN",
    "Postal": "55012-0176",
    "BankAccount": "*****0207",
    "PaymentStatus": "Paid"
    }
    ],
    }
    }
    ],
    }
    }
    ],
    }
    }
    }




    How can I retrieve SupplierInvoiceHeader and the below operations in my service call? I'm able to produce data until SupplierInvoiceList with the below code:



    0
    down vote
    accept
    $.ajax({url:"/wps/proxy/http/10.249.114.31:8009/soa-infra/resources/SupplierPortal/GetSupplierPOListService!1.0/GetSupplierPOListService/Get?RecordName=OH_ESA_P_AL_LVW&VendorId=0000099475&VendorSetid=STATE&DateFrom=2014-01-01&DateTo=2015-01-01&ShowDetail=Y&POId=", dataType:'json'

    }).
    then(function(poInvoiceData) {
    poInvoiceList = poInvoiceData.SupplierPOList.SupplierPOListDetails.SupplierPOHeader;
    poInvoiceList1 = poInvoiceList.SupplierInvoiceList.SupplierInvoiceHeader;
    // poInvoiceList2 = poInvoiceList1.SupplierInvoiceHeader;
    console.log("poInvoiceData",poInvoiceData);
    console.log("poInvoiceList",poInvoiceList);
    poInvoiceTemplate = generatePOInvoice(poInvoiceList1);
    $("#poInvoiceListOutput").html(poInvoiceTemplate);

    });

    function generatePOInvoice(poInvoiceList1) {
    let poInvoiceTemplate = '';
    for (poInvoice of poInvoiceList) {
    console.log("poInvoice=",poInvoice);
    poInvoiceTemplate+=`<tr width=100%>
    <td><a href="" style="color:black">${poInvoice.PaymentTerms}</a></td>

    </tr>`;

    }
    console.log("poInvoiceTemplate",poInvoiceTemplate);
    return poInvoiceTemplate;
    }

    Your help is highly appreciable!!!!

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: How to iterate the Json object for a web service call?

    0
    down vote
    accept
    Has this question been posted on another forum?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Dec 2016
    Posts
    6

    Re: How to iterate the Json object for a web service call?

    "yes"

  4. #4
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: How to iterate the Json object for a web service call?

    javascript is not java.
    Norm

  5. #5
    Join Date
    Dec 2016
    Posts
    6

    Re: How to iterate the Json object for a web service call?

    "I've posted in Java forum

    Couldn't find JavaScript Forum"

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: How to iterate the Json object for a web service call?

    Quote Originally Posted by shruz View Post
    "I've posted in Java forum

    Couldn't find JavaScript Forum"
    Scripting - Client side.

    [Thread moved]
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    Dec 2016
    Posts
    6

    Re: How to iterate the Json object for a web service call?

    I'm able to loop and able to display the data but was facing some issue that unable to display all the values in the list even though they have the respective invoice details in the pay load:

    dataType:'json',
    type:'GET',
    contentType : 'application/json',
    url:url,
    }).
    then(function(poInvoiceData) {
    alert(JSON.stringify(poInvoiceData));
    poInvoiceList = poInvoiceData.SupplierPOList.SupplierPOListDetails.SupplierPOHeader;
    $.each(poInvoiceList[0].SupplierInvoiceList.SupplierInvoiceHeader, function( invoiceIndex, invoiceDetails ){

    Suggestions are appreciated!!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured