Home c++ JSON file parsing on C++

JSON file parsing on C++

Author

Date

Category

downloaded JSON.HPP file and I need to be sparking this File . I need to first spark out “Titles”. And then on these keys, sparking already “irises”.

That’s what I have happened.

# include & lt; iostream & gt;
#Include & lt; vector & gt;
#Include & lt; String & GT;
#Include & lt; fstream & gt;
#Include & lt; unordered_map & gt;
#include "json.h"
Using Namespace nlohmann;
Using Namespace STD;
INT MAIN () {
  Ifstream SRC ("Irises.json");
  JSON JSN;
  SRC & GT; & GT; jsn;
  Const Auto & Amp; irises = jsn ["Irises"];
  Const Auto & Amp; Titles = jsn ["titles"];
  Return 0;
}

During the program, I need to get the values ​​of the signs of each flower.

Tell me how I can resolve this file, give an example code.


Answer 1, Authority 100%

It is all Parsit itself. Here is an example, as you can take and remove in the form of a table (primitive of course, but still).

int main () {
  Ifstream SRC ("Irises.json");
  JSON JSN;
  SRC & GT; & GT; jsn;
  Const Auto & Amp; irises = jsn ["Irises"];
  Const Auto & Amp; Titles = jsn ["titles"];
  Std :: Vector & lt; Std :: String & GT; title; // Array of headlovkov
  For (Const Auto & Amp; T: TITLES) {
   STD :: STRING S = T;
   title.push_back (s); // Fill it
  }
  For (Const Auto & Amp; IR: Irises) {
   STD :: COUT & LT; & LT; IR ["Class"]; // Display name
   For (Const Auto & Amp; ST: TITLE) {
    STD :: COUT & LT; & LT; "\ t" & lt; & lt; IR [ST]; // Use the array of headers
   }
   STD :: COUT & LT; & LT; "\ n"; // Well, the row translation
  }
  Return 0;
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions