Json Reader Question

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
soa
Posts: 287
Joined: Mon Dec 07, 2015 3:15 pm

Json Reader Question

Post by soa » Tue May 15, 2018 10:31 am

I have the following JSON and I'm trying to extract the array of values for textPasted & timeBlurred using XPRIM_RandomAccessJsonReader but there are no examples given for arrays and I can't make sense of the errors I'm getting. Can anyone help with this?

{
"f2": {
"textPasted": ["220305", "123456"]
},
"f1": {
"timeBlurred": [62.354,23.123]
}
}

tsupartono
Posts: 74
Joined: Wed Jan 25, 2017 11:12 am

Re: Json Reader Question

Post by tsupartono » Tue May 15, 2018 11:06 am

For short arrays, the easiest would be this:

Code: Select all

For Each(#Item) In(#JsonReader.ReadArrayWithName( 'textPasted' ))
   * Process #Item
Endfor

soa
Posts: 287
Joined: Mon Dec 07, 2015 3:15 pm

Re: Json Reader Question

Post by soa » Tue May 15, 2018 11:28 am

Thanks Tony

I've been down this path but when I try to access #item as in

#wrk5000 = #item I get 'Feature Item is keyed. Supply keys inside <>...

and if I try

#wrk5000 := #item.asstring I get #wrk5000 (string) is not assignment compatible with #item.assstring. There is no AsNative String method

soa
Posts: 287
Joined: Mon Dec 07, 2015 3:15 pm

Re: Json Reader Question

Post by soa » Tue May 15, 2018 11:53 am

Ok got it, the #item is a unicode string so I need to assign it to an *NVARCHAR then use the asnative string method on that to get the value

Define Field(#str) Type(*NVARCHAR) Length(5000)

#Reader.SetSourceString String(#CATRSPFSV)
For Each(#Item) In(#Reader.ReadArrayWithPath( 'f2/textPasted' ))
#str := #item.AsString
#WRK5000 := #str.AsNativeString
Endfor

Thanks for steering me back on the right track.

Post Reply