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

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

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 992 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 18 Jan 2019, 08:25 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
            }]
        }]
    }
    
    J 1 Reply Last reply 18 Jan 2019, 08:26
    0
    • P pokemonsrqt
      18 Jan 2019, 08:25

      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
              }]
          }]
      }
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 18 Jan 2019, 08:26 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 18 Jan 2019, 08:48 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.

        J 1 Reply Last reply 18 Jan 2019, 09:01
        0
        • P pokemonsrqt
          18 Jan 2019, 08:48

          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.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 18 Jan 2019, 09:01 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 18 Jan 2019, 10:05 last edited by
            #5

            Thanks! That helped big time!

            1 Reply Last reply
            0

            1/5

            18 Jan 2019, 08:25

            • Login

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