1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Resolved Extract Value(s) From Json

Discussion in 'Development' started by Rod Anderson, Aug 8, 2017.

  1. Rod Anderson

    Rod Anderson Member

    I'm calling a rest service and getting back the below JSON. I tried to build a dynamic dataset but since the the JSON document omits the outer object I get errors 15358 and 15374 which I can't seem to find a work around.

    I then tried picking the specific data I need using:

    oObject = CAST(oEntity, JsonObject).
    oNestObject1 = oObject:GetJsonObject(""). /* this should be the name of the outer object */
    cRequestID = oNestObject1:GetJsonText('requestId').

    But without the name of the outer object I can't grab the value(s). Any ideas as to how to resolve this?

    Thanks in advance,

    Rod



    {
    "requestId": "f9f471c9-4c3f-403a-86e7-aadae573350f",
    "application": "XCDS",
    "genDt": "",
    "createDt": "2017-08-07T14:35:14.931-04:00",
    "timeToLive": 60,
    "runAfterDate": "",
    "runAfterRequestId": null,
    "fixId": null,
    "fixOption": null,
    "status": "Maintenance never sent",
    "sent": false,
    "_links": [{
    "rel": "appList",
    "uri": "http:\/\/smisdev.mydomain.com\/polling\/v1\/app\/XCDS",
    "methods": [
    "GET",
    "POST",
    "OPTIONS"
    ]
    },
    {
    "rel": "operations",
    "uri": "http:\/\/smisdev.mydomain.com\/polling\/v1\/f9f471c9-4c3f-403a-86e7-aadae573350f\/operations",
    "methods": [
    "GET",
    "POST",
    "DELETE",
    "OPTIONS"
    ]
    },
    {
    "rel": "self",
    "uri": "http:\/\/smisdev.mydomain.com\/polling\/v1\/f9f471c9-4c3f-403a-86e7-aadae573350f",
    "methods": [
    "GET",
    "POST",
    "PUT",
    "OPTIONS"
    ]
    },
    {
    "rel": "stores",
    "uri": "http:\/\/smisdev.mydomain.com\/polling\/v1\/f9f471c9-4c3f-403a-86e7-aadae573350f\/stores",
    "methods": [
    "GET",
    "PUT",
    "POST",
    "DELETE",
    "OPTIONS"
    ]
    }
    ]
    }
     
  2.  
  3. TomBascom

    TomBascom Curmudgeon

    Do a little string manipulation to add the missing outer object. Something like:

    JSONdata = substitute( '~{"ProDataSet": &1 ~}', JSONdata ).

    should do the trick.
     
  4. Rod Anderson

    Rod Anderson Member

    Thanks Tom, I finally figured out that if I cast oEntity (the JSON response) to a JsonObject then I could access the properties directly:

    Code (progress):
    1.  
    2. oJsonObject = CAST(oEntity, Jsonobject).
    3. myrequestID = oJsonObject:getJsonText("requestId").
    4.  
    5. /* and read the _links into an array */
    6.  
    7.  DEF VAR oJsonArray  AS JsonArray         NO-UNDO.
    8. oJsonArray  = oJsonObject:GetJsonArray('_links').
    9.  
     

Share This Page