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 Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
jsonjson parserencodingunicode
4 Posts 2 Posters 1.3k Views 1 Watching
  • 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 last edited by Mixlu
    #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 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 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
        0
        • M Mixlu

          @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 last edited by Bonnie
          #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

          • Login

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