How to handle the escape-character in json-string

Posted by DenDuze on 15-Jul-2019 08:11

Hi,
I guess this will be a stupid question and an easy solution is available ....

I have a memprt with a json-string that I got back from a service.
In that json-string we have data where escape-characters are used, like \" wheels or display 19\".
When I'm processing that data of course I do not want that these characters are written ro the DB.

So how can I remove these escape-characters in a json-string (processed by the ObjectModelParser)?
I could always use assing ... = replace(json-string value, '\"', '"').
But that's not really a good idea because I would need to do that on every string-value that I get from that json while processing that json (I never know if a value can and will contain this escape-character)

I guess there will be some easy solution to this but I can't find it

Regards
Didier

All Replies

Posted by goo on 15-Jul-2019 09:32

If you put the mempntr into a jsonObject and then use JsonObject:GetJsonText() or JsonObject:GetLongchar(), do you then have the same problem?
 
//Geir Otto

Posted by DenDuze on 15-Jul-2019 09:48

Hi Otto,

That's what I do.

assign          

     parser         = new ObjectModelParser()

     jsonResponse   = cast(parser:Parse(mptrOut), JsonObject)

     jsonResponse   = jsonResponse:GetJsonObject("responseDetails")

     jsonResponse   = jsonResponse:GetJsonObject("vehicle").

an then I use for example

assign v-INdescription = string(JsonResponse:GetJsonText("itemDescription").

regards

Didier

Posted by marian.edu on 15-Jul-2019 10:02

GetCharacter should give you the unescaped string, GetJsonText gives you the actual text as serialized in JSON.


Marian Edu

Acorn IT 
www.acorn-it.com
www.akera.io
+40 740 036 212

Posted by goo on 15-Jul-2019 10:34

What about GetLongchar(), does that give the same as GetJsonText() ?
 
//Geir Otto
 

Posted by DenDuze on 15-Jul-2019 11:28

Arggh, ok that's clear (both suggestions work fine).

Thes tupid thing is that I used those in some other program in the past but tried here with GetJsonText so that I could prevent the check on what datatype a value was. But that was clearly a bad idea because then I have the problem with the escape-character.

No problem, will adjust my code to use jsonObject:Get<depends on datatype>

Thanks

This thread is closed