How to handle the escape-character in json-string - Forum - OpenEdge Development - Progress Community

How to handle the escape-character in json-string

 Forum

How to handle the escape-character in json-string

This question is not answered

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
  • 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
  • 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

  • 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

  • What about GetLongchar(), does that give the same as GetJsonText() ?
     
    //Geir Otto
     
  • 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