2

I have a JsonArray of Integers example - [1000, 1001, 1002,.....,1100].

I need to traverse this JsonArray so that I can call my function one by one.

I tried

function Amen returns JsonObject (input code as JsonArray, input lang as char):

def var Amenities as JsonObject.
    Amenities = new JsonObject().
    Amenities:Add("Code", code).
    for first inditaal where string(inditaal.indi-nr) = string(code) and inditaal.taal-code = lang no-lock.
    end.
        Amenities:Add("Description", inditaal.inditaal-oms).

return Amenities.

end function.

define variable code as JsonArray no-undo init [10400, 10239, 10205].

def var result as JsonArray.
result = new JsonArray().

def var lineObj as JsonArray.

do i = 1 to code :length:
    lineObj = new JsonArray().
    lineObj = code :GetJsonArray(i).
    result:Add(Amen(lineObj)).
end.

I am unable to get integers from JsonArray code. Is there any other way to do it?

As I am new to this language, I am unable to do so and also I'm not finding anything in the documentation. Please Help!

Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
Mr Voice
  • 145
  • 9

1 Answers1

1

To add an Integer extent (ABL Array) to the JsonArray, use the Add method.

To loop through the JsonArray, iterate to the JsonArray's Length and use GetInteger(i) to retrieve a single value.

USING Progress.Json.ObjectModel.* FROM PROPATH . 

define variable code as INTEGER EXTENT no-undo init [10400, 10239, 10205].

DEFINE VARIABLE oJsonArray AS JsonArray NO-UNDO . 
DEFINE VARIABLE i AS INTEGER     NO-UNDO.

oJsonArray = NEW JsonArray () . 

oJsonArray:ADD (code) . 

do i = 1 to oJsonArray:length:
    message oJsonArray:GetInteger (i) .
end.
Mike Fechner
  • 6,627
  • 15
  • 17