I’m having trouble reading a JSON that has a extent[6] data property.
This is the JSON:
{
"SalesRep": [
{
"SalesRep": "BBB",
"RepName": "Brawn , Bubba B.",
"Region": "East",
"MonthQuota": [
1600,1648,1697,1748,1800,1854
]
}
]
}
I want to read the second numerical value (extent[2]=1648).
This is my pgm:
myParser = NEW ObjectModelParser( ).
myConstruct = myParser:ParseFile("JsonRaro.json").
myJsonObj2 = CAST(myJsonObj1:GetJsonArray("ttSalesRep"):GetJsonObject(1),JsonObject).
MESSAGE
"2 " STRING( myJsonObj2:GetJsonText("RepName") ) SKIP /*result="2 Brawn , Bubba B."*/
"3 " STRING( myJsonObj2:GetJsonText("MonthQuota") ) SKIP /*result="
[1600,1648,1697,1748,1800,1854]"*/
"3a " STRING( myJsonObj2:GetJsonArray("MonthQuota"):GetJsonArray(2,1) ) SKIP /*ERROR*/
VIEW-AS ALERT-BOX.
2
Answers
You only need to get the item from the array, not another array.
So this
should be
I see your are using a
JsonObject
, which can do the trick and is very flexible.If the structure of the
json
is simple and is valid to map to a temp-table, you can use something like:The downside is that you need to define field
MonthQuota
with a fixed extend number (but I guess 12 is enough).