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"
]
}
]
}
Hi
Try reading it in as an JsonArray instead of an JsonObject
Ok I give up being stupd.
if TYPE-OF(oEntity, JsonObject) equates to true when it comes back from the REST service then how to I transform that to a JsonArray without out writing it to a file and reading it back in?
The array'll have a name - you can get it that way. Here's an example from the 11.6 docs -
DEFINE VARIABLE CustInfo AS LONGCHAR NO-UNDO. DEFINE VARIABLE myObj AS JsonObject NO-UNDO. DEFINE VARIABLE myArray AS JsonArray NO-UNDO. myObj = CAST(myParser:Parse(CustInfo), JsonObject). myArray = myObj:GetJsonObject("CustOrder"):GetJsonArray("ttOrder").
You can’t transform it to an array, unless you put that object inside an array but what would be the gain of this?
Tim, Thank you for the responce. I looked at that example previoulsy but it has a outer object called CustOrder and an inner called ttOrder. I don't have anything to reference (see original json repsonce). Having said that it's problably my ignorance so please feel free to educate away:)
use the oJsonObject:GetNames( ) aPI to get a list of names of items it contains. You can then use oJsonObject:GetType() to find out the type of each name.
See the JsonObject docs for more details.
The lightbulb finally came on. Thanks to everyone.