API - array in JSON of body of the request
Posted: Fri Oct 11, 2024 6:21 pm
Hi,
I am working on a POST request for an API and in the body of my request I have a JSON object. In this JSON object I have 3 elements, two being fields and one being an array. Example:
{
"NaceArray": ["41","42","43","71"],
"CODLAN": "1",
"NBRMAX": 0
}
In the API source code, if I want to access the data of the JSON object, I did the following:
However, I am having trouble assigning the data in the array to a list or a collection so that I can loop in the array. I have tried by defining a working list or a collection of strings and then assigning the array to them but it does not work. Example:
I have this error: "The class of component #NaceCol is not assignment compatible with #NaceObjectReq.NaceArray".
Also, if I try to loop directly in the array using selectlist or the For Each commands, I have these errors:
Although I can access the array data one by one like this: #NaceObjectReq.NaceArray<1>, I would like to know if there is a "cleaner" way to do this.
Thanks for your help,
Romain
I am working on a POST request for an API and in the body of my request I have a JSON object. In this JSON object I have 3 elements, two being fields and one being an array. Example:
{
"NaceArray": ["41","42","43","71"],
"CODLAN": "1",
"NBRMAX": 0
}
In the API source code, if I want to access the data of the JSON object, I did the following:
Code: Select all
#NaceObjectReq <= #Operation.Request.ContentJson
#CodeLangue := #NaceObjectReq.CODLAN
#NbrMax := #NaceObjectReq.NBRMAXCode: Select all
Def_List Name(#NaceList) Fields(#CODNAC) Type(*WORKING) Entrys(*MAX)
Define_Com Class(#PRIM_LCOL<#STD_ALPHA>) Name(#NaceCol) Reference(*DYNAMIC)
...
#NaceList <= #NaceObjectReq.NaceArray
#NaceCol<= #NaceObjectReq.NaceArray
Also, if I try to loop directly in the array using selectlist or the For Each commands, I have these errors:
Although I can access the array data one by one like this: #NaceObjectReq.NaceArray<1>, I would like to know if there is a "cleaner" way to do this.
Thanks for your help,
Romain