Reading json files in C++

前端 未结 7 2227
梦如初夏
梦如初夏 2021-02-01 03:17

I\'m trying to read in a JSON file. So far I have focused on using the jsoncpp library. However, the documentation is quite hard to understand for me. Could anyone

7条回答
  •  面向向阳花
    2021-02-01 04:00

    Here is another easier possibility to read in a json file:

    #include "json/json.h"
    
    std::ifstream file_input("input.json");
    Json::Reader reader;
    Json::Value root;
    reader.parse(file_input, root);
    cout << root;
    

    You can then get the values like this:

    cout << root["key"]
    

提交回复
热议问题