Read JSON

    0

    1

    Giovanny Gongora

    Codiga's C++ Recipes

    Use nlohmann lib to read JSON

    #include <iostream>
    #include <nlohmann/json.hpp>
    #include <iomanip>
    #include <vector>
    #include <fstream>
    
    using json = nlohmann::json;
    int readJSON(){
      std::ifstream is("i_data.json");
      json i_data;
      is >> i_data;
      std::vector<std::string> ids = i_data["id"];
      std::vector<int> counts = i_data["count"];
      return 0;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.