PDA

View Full Version : More Character Encodings



Albin
20-Apr-2017, 02:33 AM
Hi.

I just started again with the Office365 API, trying to get it to work.
I can get my mail folders, read my mails, delete mails.
But When I try to create and send mail I have somewhat the same problem I had with reading mails.
If I create a draft mail with a subject or body containing special characters (Swedish Å Ä Ö), then the operation fails with HTTP error 400.
"Bad Request. Cannot read the request body."
If I remove the special characters everything works great.

Following the code it runs thru a procedure called "Procedure StructToJson", but it does not seem to change the special characters here. Should it?

claudiomsj
21-Apr-2017, 06:19 AM
JSON uses UTF8, and it also has some other specific rules about escaping characters. I would assume that any non english-standard character would have to be escaped in a JSON string. I'm also sure that the JSON parser that I use would fail to parser any json with the character you are talking about.

Cheers

Albin
21-Apr-2017, 06:59 AM
JSON uses UTF8, and it also has some other specific rules about escaping characters. I would assume that any non english-standard character would have to be escaped in a JSON string. I'm also sure that the JSON parser that I use would fail to parser any json with the character you are talking about.
Cheers

Thanks Claudio. Thanks to this I was able to adjust the Json Parser and now my special characters work.

Mike Peat
22-Apr-2017, 06:12 AM
Excellent - you solved it without me! :)

I was busy yesterday, but groaning internally, thinking "Oh no, not this again".

Well done!

Mike

wila
23-Apr-2017, 05:17 AM
Hi Albin,

Thanks Claudio. Thanks to this I was able to adjust the Json Parser and now my special characters work.
As I admittedly am too lazy to go research this, but yet still curious about the details, do you mind sharing how you adjusted the Json parser?

--
Wil

claudiomsj
24-Apr-2017, 11:52 AM
Hello Wila,

I can't comment on how Albin fixed his code... On my case, I use i18n (internationalisation) for encoding in general, where regular UTF8 is applied. However, because JSON has its own syntax notation, it is necessary to also escape the character that could break the json generated content... so there are some specific escaping standardised for JSON.

Cheers,

Albin
25-Apr-2017, 01:30 AM
Hi Albin,

As I admittedly am too lazy to go research this, but yet still curious about the details, do you mind sharing how you adjusted the Json parser?

--
Wil

Hi Wil.

Inside the procedure

Procedure _DocToString Integer iObjectType tJsonNode[] stNodes String ByRef sJson Boolean bReadEasy Integer iLevel
I pass my string values to a function that returns the string as UTF8. (Function below).
That way, the special characters is transformed and the json string will work.


Function OemToUtf8String Global String sOemString Returns String Address aString
String sUtf8String
Boolean bVoid
trim sOemString to sOemString
Move (OemToUtf8Buffer((AddressOf(sOemString)), CStringLength(sOemString))) to aString
Move aString to sUtf8String
Move (Free(aString)) to bVoid
Function_Return sUtf8String
End_Function

wila
25-Apr-2017, 04:50 AM
Interesting.

Thanks Albin (and Claudio) for sharing the details.
--
Wil