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. QJson Parsing help request
Forum Updated to NodeBB v4.3 + New Features

QJson Parsing help request

Scheduled Pinned Locked Moved General and Desktop
json
3 Posts 3 Posters 1.5k Views 2 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.
  • metaDomM Offline
    metaDomM Offline
    metaDom
    wrote on last edited by metaDom
    #1

    Hey, guys!

    I have the following json data:

    {
    "IssueInstant": "2015-03-19T14:54:41.563054Z",
    "NotAfter": "2015-03-19T22:54:41.563054Z",
    "id": "12345",
    "cat": {
    "test": [{
    "a": "aData",
    "b": "bData",
    "c": "cData",
    "d": "dData",
    "e": "eData"
    }]
    }
    }

    I want access to the a-e values. Right now I'm doing:

    QJsonDocument jsonResponse = QJsonDocument::fromJson(ba);
    QJsonObject jsonObj = jsonResponse.object();
    id = jsonObj["id"].toString();
    

    This works fine to get upper level values, but not the sub ones. Any ideas? Thanks in advance!

    M JKSHJ 2 Replies Last reply
    0
    • metaDomM metaDom

      Hey, guys!

      I have the following json data:

      {
      "IssueInstant": "2015-03-19T14:54:41.563054Z",
      "NotAfter": "2015-03-19T22:54:41.563054Z",
      "id": "12345",
      "cat": {
      "test": [{
      "a": "aData",
      "b": "bData",
      "c": "cData",
      "d": "dData",
      "e": "eData"
      }]
      }
      }

      I want access to the a-e values. Right now I'm doing:

      QJsonDocument jsonResponse = QJsonDocument::fromJson(ba);
      QJsonObject jsonObj = jsonResponse.object();
      id = jsonObj["id"].toString();
      

      This works fine to get upper level values, but not the sub ones. Any ideas? Thanks in advance!

      M Offline
      M Offline
      moellney
      wrote on last edited by
      #2

      @metaDom said:

      Hey, guys!

      I have the following json data:

      {
      "IssueInstant": "2015-03-19T14:54:41.563054Z",
      "NotAfter": "2015-03-19T22:54:41.563054Z",
      "id": "12345",
      "cat": {
      "test": [{
      "a": "aData",
      "b": "bData",
      "c": "cData",
      "d": "dData",
      "e": "eData"
      }]
      }
      }

      I want access to the a-e values. Right now I'm doing:

      QJsonDocument jsonResponse = QJsonDocument::fromJson(ba);
      QJsonObject jsonObj = jsonResponse.object();
      id = jsonObj["id"].toString();
      

      This works fine to get upper level values, but not the sub ones. Any ideas? Thanks in advance!

      It looks that cat is an Object with a member test. Test itself is an Array which contains one Object. This Object has the members a to e. So you have to convert cat to an jsonobject, grab the test member, convert this to an jsonarray, grab the only and first entry, convert this to jsonobject and access the members a to e ...

      1 Reply Last reply
      0
      • metaDomM metaDom

        Hey, guys!

        I have the following json data:

        {
        "IssueInstant": "2015-03-19T14:54:41.563054Z",
        "NotAfter": "2015-03-19T22:54:41.563054Z",
        "id": "12345",
        "cat": {
        "test": [{
        "a": "aData",
        "b": "bData",
        "c": "cData",
        "d": "dData",
        "e": "eData"
        }]
        }
        }

        I want access to the a-e values. Right now I'm doing:

        QJsonDocument jsonResponse = QJsonDocument::fromJson(ba);
        QJsonObject jsonObj = jsonResponse.object();
        id = jsonObj["id"].toString();
        

        This works fine to get upper level values, but not the sub ones. Any ideas? Thanks in advance!

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        Hi,

        @metaDom said:

        QJsonDocument jsonResponse = QJsonDocument::fromJson(ba);
        QJsonObject jsonObj = jsonResponse.object();
        id = jsonObj["id"].toString();
        

        This works fine to get upper level values, but not the sub ones. Any ideas? Thanks in advance!

        You get the sub ones in the same way. "cat" is an object, so you convert the value to an object:

        QJsonObject catObj = jsonObj["cat"].toObject();
        

        "cat" is an object that contains "test", which is an array that contains 1 object that contains your 5 string elements.

        This page might be useful: http://doc.qt.io/qt-5/qjsonvalue.html

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        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