Create QByteArray JSON with special characters (é, ...) as unicode (\uxxxx)
-
wrote on 2 Jul 2020, 13:18 last edited by Mixlu 7 Feb 2020, 13:20
I would like to create a simple JSON structure like follow :
{ "é" : 1 }
And to finally get it as a valid JSON
QByteArray
.Here is my code in order to achieve this :
QJsonObject data; data.insert("é", 1); QJsonDocument jsonDoc(data); QByteArray bjsonData = jsonDoc.toJson();
But here the "é" is stored as "\xC3\xA9", it is the UTF-8 representation of the character but I would like to get "\u00e9" instead (the unicode code point) as specified by the JSON RFC.
Is there a way to get escaped Unicode value instead of escaped utf-8 value ?
-
wrote on 2 Jul 2020, 13:42 last edited by
It is not escaped.
It is just the QDebug output of unprintablechar
.
If you convert the QByteArray to a QString withQString::fromUtf8()
, it is still a"é"
. -
wrote on 2 Jul 2020, 13:54 last edited by
@Bonnie said in Create QByteArray JSON with special characters (é, ...) as unicode (\uxxxx):
unprintable
Ahh fine, thanks for the reply.
And so is there a way to get the Unicode escaped format ?
-
@Bonnie said in Create QByteArray JSON with special characters (é, ...) as unicode (\uxxxx):
unprintable
Ahh fine, thanks for the reply.
And so is there a way to get the Unicode escaped format ?
wrote on 2 Jul 2020, 14:21 last edited by Bonnie 7 Feb 2020, 14:23@Mixlu
What do you mean by "Unicode escaped format"?
Normal characters won't be escaped, even a character likeé
also doesn't need to be escaped.
If you use some special characters like\0
, then it will be escaped to\u0000
1/4