Page 1 of 1
Retrieving element name from JSON Message
Posted: Thu Jun 13, 2019 11:32 pm
by Eugene
Is there a way to retrieve the element name from a JSON message as well as the value?
I'm using the URL below to retrieve a list of the exchange rates. I now want to read through the returned JSON message and not only retrieve the value but also the element (key) name.
https://api.exchangeratesapi.io/latest
{
base: "EUR",
rates: {
BGN: 1.9558,
NZD: 1.7206,
ILS: 4.0544,
RUB: 73.0227,
CAD: 1.5002,
USD: 1.132,
},
date: "2019-06-11"
}
Thanks in advance.
Eugene
Re: Retrieving element name from JSON Message
Posted: Fri Jun 14, 2019 4:38 pm
by tsupartono
I'm assuming you are going to do this on your server-side code (server module).
The best way right now is to use
PRIM_JSON.Reader
See
https://apps.lansa.com/lansav14sp2/dem/xdemow_12.html for usage example.
Have a look at this forum post as well:
viewtopic.php?f=3&t=2046#p5374
While using
PRIM_JSON.Reader is not the most straightforward thing to do, it would be the best solution for now until
EPC142060 is released - after which you can use
PRIM_JSON.Document, which is much easier to use (currently there are issues getting decimal values using
PRIM_JSON.Document).
If this is just for demonstration, you can also do it client side using a widget.
Re: Retrieving element name from JSON Message
Posted: Fri Jun 21, 2019 9:56 am
by soa
We don't have EPC142060 installed as it is not released but in another post I saw these declarations
Define_Com Class(#PRIM_JSON.Document) Name(#lDocument)
Define_Com Class(#PRIM_JSON.Object) Name(#lRequestObject) Reference(*DYNAMIC)
Define_Com Class(#PRIM_JSON.Member) Name(#lRequestMember) Reference(*DYNAMIC)
Define_Com Class(#PRIM_JSON.Array) Name(#lLinks) Reference(*DYNAMIC)
These all seem to work (i.e. the IDE finds them) our current install (up to EPC14240). Are these classes functional at this EPC level. Can I start playing with them now in anticipation of 142060 or have they changed much. Do you have any example code?
Re: Retrieving element name from JSON Message
Posted: Fri Jun 21, 2019 11:48 am
by tsupartono
You can play around with it now, there won't be any change in the API itself.
The upcoming
EPC142060 corrects some issues in
PRIM_JSON.Document:
- LoadFromString does not take unicode string
- LoadFromFile missing path parameter
- Getting decimal value throws an error
Also, if you use the publishing web services feature, the EPC after 142060 (
EPC142070) introduces a new (better) way to read/write the request/response data, so you may not even need to use
PRIM_JSON.Document at all.
Re: Retrieving element name from JSON Message
Posted: Fri Jun 21, 2019 12:11 pm
by soa
Thanks tony