Picture of tsn
Registered 4 years 358 days
tsn Tuesday, 10 November 2020, 08:13 PM
json decoding and utf-8
Hi guys,

I've faced with the following issue:
const char* raw = "{\"value\":\"(\\u00fc)\"}";
char buf[128]; strcpy(buf, raw);
json_io json(buf);
json.decode();
word base = json.get_object(JSON_ID_ROOT, 0);
const char* value = json.get_string(base, "value");
printf("value=%s length=%zu\n", value, strlen(value));
The output of this test is the following:
value=() length=2
I would expect it to return me "(\u00fc)" rather than "()".

Is it expected behavior? If so, what is the correct way to get a full string as it is from the json?

Best regards,
Sergey
Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 179 days
Daniel Deterding (innovaphone) Wednesday, 11 November 2020, 08:22 AM
Re: json decoding and utf-8
Hi Sergey,

according to the JSON escaping rules, \u has a specific meaning:
https://tools.ietf.org/id/draft-ietf-json-rfc4627bis-09.html#rfc.section.7

If you want to have (\u00fc) as string, you must use two backslashes:
const char* raw = "{\"value\":\"(\\\\u00fc)\"}";

Greetings,
Daniel
Picture of tsn
Registered 4 years 358 days
tsn Wednesday, 11 November 2020, 09:05 AM
Re: json decoding and utf-8
Hi Daniel,

Thank you for quick reply.

This json is generated by third-party API and I can' change the payload.
So they send us properly encoded unicode characters. And as far as I was not able to get either unicode character or it's code I thought that something is wrong.

Could you please clarify how to use decoder to get the full payload from json?

Best regards,
Sergey
Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 179 days
Daniel Deterding (innovaphone) Wednesday, 11 November 2020, 11:03 AM
1 of 1 users consider this post helpful
Re: json decoding and utf-8
Hi Sergey,

our internal JSON decoding didn't decode values greater than \u001f.
I checked in a fix for this which will be included in 13r1 SR21.
This will be published normally in december.

Please tell us, if you are blocked by this and need a DVL release earlier.

Greetings,
Daniel
Picture of tsn
Registered 4 years 358 days
tsn Wednesday, 11 November 2020, 11:13 AM
Re: json decoding and utf-8
Hi Daniel,

Thank you for confirmation.
It would be great if I can have a preliminary release so I can check and confirm if the issue is completely fixed before the official release.
Please let me know if it possible so I can test a new version on my side.

Best regards,
Sergey
Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 179 days
Daniel Deterding (innovaphone) Wednesday, 11 November 2020, 12:33 PM
Re: json decoding and utf-8
You can find a DVL SDK version here:
http://download.innovaphone.com/ice/download/p/published/Firmware%20Version%2013r1/132624/sdk.zip

Rename your local sdk directory inside your app and extract the sdk directory inside the zip file instead there and rebuild your app.

Greetings,
Daniel
Picture of tsn
Registered 4 years 358 days
tsn Wednesday, 11 November 2020, 01:35 PM
Re: json decoding and utf-8
Hi Daniel,

Thank you for this build. I've checked and it works good to me.
Will look forward to the next official release.

Best regards,
Sergey
← You can define your color theme preference here