I'm trying to parse a JSON string that looks like this:
{
"success":false,
"response_code":1,
"status_message":"One or more errors has occurred.",
"errors": {
"45":["Please provide valid Checking Account Number"],
"46":["Please provide valid Transit Routing Number"],
"35":["Please provide a valid Credit Card Number"],
"43":["Please provide a valid Expiration Date"]
}
}
I'm having issues with the "errors" object.
I don't want to call jsonObject:GetArray() for every possible number that may be in there.
Is there a way to iterate through the contents of this object?
Thanks
Hi Ken,
Here is a (incomplete, sloppy) snippet Ithat gives you a general idea about how you could achieve this.
define variable jsonErrors as Progress.Json.ObjectModel.JsonArray.
jsonErrors = jsonObject:GetJsonArray('errors').
do iCount = 1 to jsonErrors :length:
assign lineObj = new Progress.Json.ObjectModel.JsonObject()
lineObj = jsonErrors:GetJsonObject(iTeller1)
cNames = lineObj:getNames().
do iTeller2 = 1 to extent(cNames):
cName = cNames[iTeller2]. // this gives you: 45, 46, etc,
cValue = string(lineObj:GetJsonText(cName)). // this gives you: Please provide valid Checking Account Number, etc
end.
end.
Hi Ken,
Here is a (incomplete, sloppy) snippet Ithat gives you a general idea about how you could achieve this.
define variable jsonErrors as Progress.Json.ObjectModel.JsonArray.
jsonErrors = jsonObject:GetJsonArray('errors').
do iCount = 1 to jsonErrors :length:
assign lineObj = new Progress.Json.ObjectModel.JsonObject()
lineObj = jsonErrors:GetJsonObject(iTeller1)
cNames = lineObj:getNames().
do iTeller2 = 1 to extent(cNames):
cName = cNames[iTeller2]. // this gives you: 45, 46, etc,
cValue = string(lineObj:GetJsonText(cName)). // this gives you: Please provide valid Checking Account Number, etc
end.
end.
I rewrote it a little, but it works Thanks!
DEF VAR cnames AS CHAR EXTENT NO-UNDO.
DEF VAR cMsgs AS CHAR EXTENT NO-UNDO.
jErrors = jsonObj:GetJsonObject("errors").
cnames = jErrors:GetNames().
EXTENT(cMsgs) = EXTENT(cnames).
DEF VAR i AS INTEGER NO-UNDO.
DO i = 1 TO EXTENT(cNames):
cMsgs[i] = jErrors:GetJsonArray(cnames[i]):GetCharacter(1).
END.
You're welcome
Thanks everyone. The main issue was that i missed the GetNames() method amongst all the other Get*() Methods listed.