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. Parsing JSON with Qt
Qt 6.11 is out! See what's new in the release blog

Parsing JSON with Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.3k Views 3 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.
  • N Offline
    N Offline
    NotYourFan
    wrote on last edited by
    #1

    Hey i want to parse a JSON.

    My JSON looks like:

    {
      "static": {
        "readFiles": {
          "balance": "statisch",
          "level1": {
            "int id": 0,
            "level2": {
              "typ": "TextField",
              "background-color": "grey"
            },
            "level1_1": {
              "int id_1": 0,
              "level2_1": {
                "typ": "TextField",
                "background-color": "grey"
              }
            }
          }
        }
      }
    }
    

    now i want to parse each level.

    The JSON-File have always the same structur, only the content can be diffrent and they can be more informations in this file.

    I want to get the content from "static" and from "level2" for example.
    How can i parse this file ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The starting point will likely be QJsonDocument.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      5
      • N Offline
        N Offline
        NotYourFan
        wrote on last edited by
        #3

        Hey @SGaist thank you for your request,

        i now this Documentation, but i dont find something how help me on my question.

        beeckscheB 1 Reply Last reply
        0
        • N NotYourFan

          Hey @SGaist thank you for your request,

          i now this Documentation, but i dont find something how help me on my question.

          beeckscheB Offline
          beeckscheB Offline
          beecksche
          wrote on last edited by
          #4

          @NotYourFan

          All described in the documentation of QJsonDocument and examples. I would suggest something like that:

          QFile file(filename);
          file.open();
          
          QJsonDocument json = QJsonDocument::fromJson(file.readAll());
          QJsonObject static = json["static"];
          QJsonObject readfiles= static ["readFiles"];
          ....
          
          
          1 Reply Last reply
          2

          • Login

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