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. Using QJson functionality to change data in nested json with arrays.
Forum Update on Monday, May 27th 2025

Using QJson functionality to change data in nested json with arrays.

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 953 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.
  • P Offline
    P Offline
    pokemonsrqt
    wrote on last edited by
    #1

    Here is a problem I have been struggling with for a few hours and am not close to solving. How can I change id and recording-id from 0 to 1.

    {
        recordings: [{
            id: 0
        }],
        data-source-storages: [{
            sample-storages: [{
                recording-id: 0
            }]
        }]
    }
    
    jsulmJ 1 Reply Last reply
    0
    • P pokemonsrqt

      Here is a problem I have been struggling with for a few hours and am not close to solving. How can I change id and recording-id from 0 to 1.

      {
          recordings: [{
              id: 0
          }],
          data-source-storages: [{
              sample-storages: [{
                  recording-id: 0
              }]
          }]
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @pokemonsrqt What did you try and what is not working?
      Start here: http://doc.qt.io/qt-5/qjsondocument.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pokemonsrqt
        wrote on last edited by
        #3

        This is where I am at

        QJsonArray recordings = obj.value(JSON::V0_1::KEYS::RECORDINGS).toArray();
        for(QJsonValue recording : recordings) {
            QJsonObject recordingObj = recording.toObject();
            recordingObj.remove("id");
            recordingObj.insert("id", DataStorage::availableRecordingId());
        }
        

        The major problem is that changing the local variable recordingObj does not change the outer variable obj that is the one I want to change.

        jsulmJ 1 Reply Last reply
        0
        • P pokemonsrqt

          This is where I am at

          QJsonArray recordings = obj.value(JSON::V0_1::KEYS::RECORDINGS).toArray();
          for(QJsonValue recording : recordings) {
              QJsonObject recordingObj = recording.toObject();
              recordingObj.remove("id");
              recordingObj.insert("id", DataStorage::availableRecordingId());
          }
          

          The major problem is that changing the local variable recordingObj does not change the outer variable obj that is the one I want to change.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @pokemonsrqt You can use http://doc.qt.io/qt-5/qjsonarray.html#operator-5b-5d

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          4
          • P Offline
            P Offline
            pokemonsrqt
            wrote on last edited by
            #5

            Thanks! That helped big time!

            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