Failed to deserialize JSON with special characters

I have a problem with deserializing a JSON string. The following string works fine:


{"Number":"7000","Id":"2","ClientName":"Contract Partners B.V.","ClientAddress":"Schootslaan 4, 4005VG  TIEL","Type":"KLA"}

But, when I use special characters like in the string below, OutSystems raises an error.

{"Number":"7001","Id":"1","ClientName":"Cöñtract Pártners B.V.","ClientAddress":"Schöötslaan 4, 4005VG  TÏÉL","Type":"KLA"}

Does anyone have any ideas on how to solve this problem?


Kind Regards,


Martin

Hi Martin,

When reporting errors, don't forget to include the actual error ;).

(EDIT: I just did a test, but it works as expected. So please include the actual error.)

"Failed to deserialize JSON to LocalRecord: Unexpected token ? in JSON at position 0" 

The JSON is retrieved from a QR-code and will be used in a mobile application.



In that case, I would bet the QR-code returns more than just the JSON, and has some prefix characters that are outside the JSON (note it complains about the very first character). Perhaps the special characters trigger a BOM being inserted?

Kilian Hekhuis wrote:

In that case, I would bet the QR-code returns more than just the JSON, and has some prefix characters that are outside the JSON (note it complains about the very first character). Perhaps the special characters trigger a BOM being inserted?

I've created a LogMessage to show what the QR-code returns. It's the excact string I showed above. 


{"Number":"7001","Id":"1","ClientName":"Cöñtract Pártners B.V.","ClientAddress":"Schöötslaan 4, 4005VG  TÏÉL","Type":"KLA"}


So what happens if you copy/paste that exact string in a test app that just does a JSON Deserialize on that string? Like I said, I tried that based on your earlier post, and god the expected result (no error).

When I copy and paste the excact same string in a testapplication, it does work. But, when I copy the string from service center (through a Log Message) and paste it on this forum, an ? appears as a prefix after I submitted the reply. 

I've tried the same in different other (non-OutSystems) application. And there the ? won't appear. 



Well, like I said, most likely there's a BOM or something like that being prefixed because of the non-ASCII characters. I would advise you to check the documentation of whatever generates the QR code with regards to this, or the documentation of the scanner, and see if you can generate the QR code without the prefix.

If that doesn't work, I would just use a Substr with an IndexOf to get the text starting with "{" and ignoring any prefix, before calling the deserialize.

Note that putting a BOM in front of JSON is something happening more often, see this Idea of mine that unfortunately got rejected.