Page 1 of 1
Reading json in VL Web
Posted: Fri Nov 29, 2019 3:46 pm
by soa
I need to read a json object in a VLWEB application.
XPRIM_RandomAccessJsonReader is not available on the web
This forum makes mention of #PRIM_JsonReader as native VLWEB component but my IDE tells me it can't be found.
How should I proceed?
Re: Reading json in VL Web
Posted: Fri Nov 29, 2019 4:03 pm
by dannyoorburg
Hi,
VL WEB client side has the PRIM_WEB.JSON object/classes.
https://docs.lansa.com/14/en/lansa016/prim_web.json.htm
Hope that helps,
Danny
Re: Reading json in VL Web
Posted: Fri Nov 29, 2019 4:40 pm
by soa
Big help Danny, thanks. Can you point me in the direction of some examples of use
I need to extract values from a json string like the following.
{
"eformlist":[
{
"Type":"SHWEX",
"Code":"ONSTG",
"EFID":"47",
"EFIID":"4707"
},
{
"Type":"SHWEX",
"Code":"ONSTI",
"EFID":"48",
"EFIID":"566"
}
]
}
Re: Reading json in VL Web
Posted: Fri Nov 29, 2019 5:24 pm
by dannyoorburg
There's many ways to navigate the JSON, depends whether you want a particular value, or iterate arrays...
I just put a simple sample together, hope this helps.
Danny
Code: Select all
Begin_Com Role(*EXTENDS #PRIM_WEB) Theme(#SYS_THEME<MaterialDesignBlue>)
Define_Com Class(#PRIM_MD.RaisedButton) Name(#Button) Caption('PRIMARY') DisplayPosition(1) Left(46) Parent(#COM_OWNER) TabPosition(1) ThemeDrawStyle('MediumTitle') Top(26)
Evtroutine Handling(#Button.Click)
Define_Com Class(#PRIM_WEB.JSON) Name(#JSON)
Define_Com Class(#PRIM_WEB.JsonElement) Name(#FormList) Reference(*DYNAMIC)
#JSON := '{"eformlist":[{"Type":"SHWEX","Code":"ONSTG","EFID":"47","EFIID":"4707"},{"Type":"SHWEX","Code":"ONSTI","EFID":"48","EFIID":"566"}]}'
#FormList <= #JSON.RootItem<"eformlist">
For Each(#FormListItem) In(#FormList)
#SYS_WEB.Alert( ("Type: " + #FormListItem<"Type">.AsString + ", EFID: " + #FormListItem<"EFID">.AsString) )
Endfor
Endroutine
End_Com
Re: Reading json in VL Web
Posted: Mon Dec 02, 2019 11:52 am
by soa
Worked out of the box, exactly what I wanted. Thanks Danny. I'll share this with the team.