Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Create QByteArray JSON with special characters (é, ...) as unicode (\uxxxx)
Forum Update on Monday, May 27th 2025

Create QByteArray JSON with special characters (é, ...) as unicode (\uxxxx)

Scheduled Pinned Locked Moved Unsolved General and Desktop
jsonjson parserencodingunicode
4 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mixlu
    wrote on 2 Jul 2020, 13:18 last edited by Mixlu 7 Feb 2020, 13:20
    #1

    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 ?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on 2 Jul 2020, 13:42 last edited by
      #2

      It is not escaped.
      It is just the QDebug output of unprintable char.
      If you convert the QByteArray to a QString with QString::fromUtf8(), it is still a "é".

      1 Reply Last reply
      2
      • M Offline
        M Offline
        Mixlu
        wrote on 2 Jul 2020, 13:54 last edited by
        #3

        @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 ?

        B 1 Reply Last reply 2 Jul 2020, 14:21
        0
        • M Mixlu
          2 Jul 2020, 13:54

          @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 ?

          B Offline
          B Offline
          Bonnie
          wrote on 2 Jul 2020, 14:21 last edited by Bonnie 7 Feb 2020, 14:23
          #4

          @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 Reply Last reply
          3

          1/4

          2 Jul 2020, 13:18

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved