Announcement

Collapse
No announcement yet.

Syntax / sample code - Unable to Read the Json Response Please help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Syntax / sample code - Unable to Read the Json Response Please help

    Hello Experts,

    I am doing a Restful - Get request in SM9.3*. The response is as follows:

    {
    "@count": 1,
    "@start": 1,
    "@totalcount": 1,
    "Messages": [],
    "ResourceName": "gtest",
    "ReturnCode": 0,
    "content": [{"gtest": {
    "ItemName": "Item Value 1234",
    "gID": 10
    }}]
    }

    I wanted to Read the value of the Json which are marked in Bold as above. I am able to Read ResourceName and Returncode but not the ItemName and gID. Dont know where it is wrong.
    ============
    var url="http://XX.XX.XX:13040/SM/9/rest/gtest?";
    var userid="XXXXXXX";
    var password="XXXX";

    var httpHeaders = new Array();
    var contentType = new Header();
    var rawJSON;

    var JSON = system.library.JSON.json();



    var parturl = "gID=10";
    url = url+parturl;

    httpHeaders = lib.smis_RestClient.createBasicAuthHttpHeaders("en ",userid, password);
    contentType.name = "Content-Type";
    contentType.value = "application/json";

    try
    {
    var connTimeout = confItem.getConfigParameterValue("http.conn.timeou t");
    var recTimeout = confItem.getConfigParameterValue("http.rec.timeout ");

    rawJSON = lib.smis_RestClient.doRESTGetRequest(url, httpHeaders,parseInt(connTimeout), 30, parseInt(recTimeout));

    print(rawJSON);
    var objResponse = JSON.parse(rawJSON);

    //print(objResponse);

    print(objResponse.ReturnCode);

    print(objResponse.ResourceName);
    // print(objResponse.Messages);
    //print(objResponse.content);



    }
    catch ( err )
    {
    print("Error! " + err.toString());
    print("Unable to get the required data");


    }

  • #2
    These two are nested in json in "content" - I assume as it might have multiple entries. you will need to ensure you cater for that, as it will not know what to parse you in you only ask for the lowest-level fields.

    Comment

    Working...
    X