Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. JSON Parse
Forum Updated to NodeBB v4.3 + New Features

JSON Parse

Scheduled Pinned Locked Moved Qt WebKit
3 Posts 2 Posters 1.2k 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.
  • F Offline
    F Offline
    Flavia
    wrote on last edited by
    #1

    Hello everyone,

    I'm trying to get used with QJson so I want to solve the example above:

    @{
    "spatialReference": {
    "wkid": 4326,
    "latestWkid": 4326
    },
    "locations": [
    {
    "name": "Bucharest, Bucureşti, Romania",
    "extent": {
    "xmin": 25.966258,
    "ymin": 44.292248000000001,
    "xmax": 26.246258000000001,
    "ymax": 44.572248000000002
    },
    "feature": {
    "geometry": {
    "x": 26.106257802000471,
    "y": 44.432248090000485
    },
    "attributes": {
    "Score": 100,
    "Addr_Type": "POI"
    }
    }
    }
    ]
    }
    @

    How can I get the "x" value? I'm using Qt 5.4 and QJsonDocument. For example, the "name" value I was successfully able to read but for now I have no idea how to do with "x" or "y". I suppose I still don't know how to read the "tree" structure.

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      Can you show us the code you used to extract "name"?

      Basically,
      @
      // Instead of this:
      locationObject["name"].toString();

      // Call this:
      locationObject["feature"].toObject();
      @

      ...and then do the same for the inner nodes.

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

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Flavia
        wrote on last edited by
        #3

        Hey,

        Now I just figure it out. Thanks :)

        However I will show the code in case there is anyone with the same problem. Maybe there is another more elegant way to get to the "x", "y" values and read it but for the moment this one is working:

        @QJsonObject jsonObj = jsonResponse.object();
        QJsonValue value=jsonObj.value("locations");
        QJsonArray array=value.toArray();

        foreach(const QJsonValue & v, array)
        { qDebug() << "Name:" << v.toObject().value("name").toString();
        qDebug() << "Longitude:" <<v.toObject().value("feature").toObject().value("geometry").toObject().value("x").toDouble();
        qDebug() << "Latitude:" <<v.toObject().value("feature").toObject().value("geometry").toObject().value("y").toDouble();
        }@

        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