Page 1 of 1
Json Reader Question
Posted: Tue May 15, 2018 10:31 am
by soa
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]
}
}
Re: Json Reader Question
Posted: Tue May 15, 2018 11:06 am
by tsupartono
For short arrays, the easiest would be this:
Code: Select all
For Each(#Item) In(#JsonReader.ReadArrayWithName( 'textPasted' ))
* Process #Item
Endfor
Re: Json Reader Question
Posted: Tue May 15, 2018 11:28 am
by soa
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
Re: Json Reader Question
Posted: Tue May 15, 2018 11:53 am
by soa
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.