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. QJsonObject create nested Object
Forum Updated to NodeBB v4.3 + New Features

QJsonObject create nested Object

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 2.0k 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.
  • X Offline
    X Offline
    xeroe
    wrote on last edited by xeroe
    #1

    Hello,
    I want to generate a nested Json Object to transmit via QWebsocket.
    I could not find any documentation or example about how to create a nested object like:

    { 
        name: "name",
        type: "randomtype",
        children: [{ 
            name: "child1",
            type: "randomtype"},
            {name: "child2",
            type: "randomtype"}]
    }
    

    Is it possible to do this somehow in the normal QJsonObject notation like:

    QJsonObject json
        {
            {"type", "textMessage"},
            {"from", fromID},
            {"to",toID},
            {"time", QTime::currentTime().toString("hh:mm:ss")},
            {"name", fromName},
            {"line", message},
            {"mode", targetMode}
        };
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi and welcome to the forums.

      Do you mean a JSON array ? ( by nested)
      Like

        QJsonArray array;
          QJsonObject Obj {
              {"xxx", "yyyy"}
          };
          
          array.append( Obj );
      
          QJsonObject json {
              {"type", "textMessage"},
              {"Array", array}
          };
      
      1 Reply Last reply
      2
      • X Offline
        X Offline
        xeroe
        wrote on last edited by
        #3

        Partially yes,
        by nested i mean a json object inside another json object, in this case its an json array in an json object.
        Ill try what you posted, as it seems to be exactly what im looking for.

        mrjjM 1 Reply Last reply
        0
        • X xeroe

          Partially yes,
          by nested i mean a json object inside another json object, in this case its an json array in an json object.
          Ill try what you posted, as it seems to be exactly what im looking for.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @xeroe
          Hi
          Ok that is also possible

           QJsonObject json {
                  {"type", "textMessage"},
                  {"subobject", Obj}
              };
          
          1 Reply Last reply
          0

          • Login

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