ASCII only chars (OpenInsight 32-bit)
At 30 JUN 2020 09:22:47AM Martin Drenovac wrote:
evening
am looking to do some .json work and have come into problem of special chars (I don't mean the OI @FM variety) are being copied out
and blowing up on the other end
i'm after a piece of code to 'ASCII'fy by data please
cheers
At 30 JUN 2020 09:28AM Andrew McAuley wrote:
Bit more detail needed. Is your database UTF8 or ANSI? If the former you could use UTF8_ANSI to convert.
World leaders in all things RevSoft
At 30 JUN 2020 09:31AM Carl Pates wrote:
Martin,
JSON is just JavaScript, so you'd do the same thing as if you were writing a string in JavaScript - i.e. escape the chars out using something like this:
encodeJSON: json = "" bPos = 1 loop ch = data[bPos,1,1] while len( ch ) bPos += getByteSize( ch ) begin case case ( ch == "\" ) json := "\\" case ( ch == "/" ) json := "\/" case ( ch == CR$ ) json := "\r" case ( ch == LF$ ) json := "\n" case ( ch == \09\ ) json := "\t" case ( ch == '"' ) json := '\"' case ( ch == \08\ ) ; // Backspace json := '\b' case ( ch == \0C\ ) ; // FormFeed json := '\f' case ( seq( ch ) < ' ' ) json := '\u' : fmt( oconv( seq( ch ), "MX" ), "R(0)#4" ) case ( seq( ch ) > 127 ) json := '\u' : fmt( oconv( seq( ch ), "MX" ), "R(0)#4" ) case OTHERWISE$ json := ch end case repeat transfer json to data return
At 30 JUN 2020 09:36AM Martin Drenovac wrote:
Cheers Carl
I think we're just plain jane UTF-8 as i'm on Oz
what's happening is, is that we're storing data that is being cut/paste from God knows where, and then when we need to ship it, it's full of shit..
cheers again Carl, i'll give you code a bash
At 30 JUN 2020 09:41AM Andrew McAuley wrote:
We had a client who'd been allowing cut and paste into the database. I think we found the + symbol under three totally separate code points. Think we blogged about it :)
World leaders in all things RevSoft
At 30 JUN 2020 05:02PM Martin Drenovac wrote:
Cheers Mr McAuley
I shall go over and have a hunt for the article
thank you mate
At 30 JUN 2020 11:19PM Donald Bakke wrote:
Martin - What library are you using to build your JSON objects? If it is SRP_JSON, characters should be properly encoded automatically.
At 01 JUL 2020 08:07PM Martin Drenovac wrote:
Cheers Don -
I am doing some proto work and not using the said routines
however, I shall do so forthwith
thank you