PDA

View Full Version : JSON Expected BEGIN_ARRAY



HenryEgal
4-Oct-2019, 09:08 AM
Hello there,

I am having a problem with my JSON format.
the service is expecting an array and I must be sending as an object.

From the service I get this message:

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $;


I am making he REST call with this:


Get HttpVerbAddrRequest of oHttp sPath pReq iSize False sVerb to iOK

Get HttpVerbAddrRequest of oHttp sPath pReq iSize False sVerb to iOK

Is there a way to send as an array?

Thanks for any direction!

Henry

Focus
4-Oct-2019, 09:17 AM
How are you building your JSON ?

If you are using the built in 19.1 classes see Mikes post here

https://support.dataaccess.com/Forums/showthread.php?63140-CreateJsonArray&p=336827&highlight=AddMemberValue#post336827

HenryEgal
4-Oct-2019, 09:32 AM
hi there,
Oh yes thanks for the link.
We are still using 19.0.

I am buidling my JSON as I have below:


Move "123456" to ltemployee.ProviderIdentification.ProviderID
Move "111111" to ltemployee.ProviderIdentification.ProviderQualifie r
Move "EmployeeCustomID" to ltemployee.EmployeeQualifier
Move "7777" to ltemployee.EmployeeIdentifier
Move "0" to ltemployee.SequenceID
Move "123456789" to ltemployee.EmployeeSSN
Move "Henry" to ltemployee.EmployeeFirstName
Move "Egal" to ltemployee.EmployeeLastName
Move "henry@horizon-is.com" to ltemployee.EmployeeEmail


Get Create (RefClass(cJsonObject)) to hojsonPath
Send DataTypeToJson of hojsonPath ltemployee

I will not be moving to 19.1 yet so I will have to research.

Thanks!
Henry

Focus
4-Oct-2019, 09:40 AM
If the whole thing need to be in array then just declare

whateverstruct[] ltemployee

Move "111111" to ltemployee[0].ProviderIdentification.ProviderQualifier

etc

HenryEgal
4-Oct-2019, 09:45 AM
Hi there,
Yes that is it.
I had tried to putting a [ at the beginning and ] a the end of the JSON and that worked.
Making my variable a struct did the same thing and that is the correct way.

Thanks so much for your help!!

Greatly appreciated!