直接包含如下头文件即可
json.hpp
下载json.hpp
二、用法包含头文件后,声明命名空间nlohmann
测试代码
#include#include #include #include "json.hpp" using namespace nlohmann; int main() { //从json串读取 std::string text = R"( { "Image": { "Width": 800, "Height": 600, "Title": "View from 15th Floor", "Thumbnail": { "Url": "http://www.example.com/image/481989943", "Height": 125, "Width": 100 }, "Animated" : false, "IDs": [116, 943, 234, 38793] } } )"; json root = json::parse(text); if (root.contains("Image")) { std::cout << root["Image"]["IDs"]; } 从文件读取 //std::ifstream in("config.json",std::ios::binary); //json root = json::parse(in); //if (root.contains("Image")) //{ // std::cout << root["Image"]["IDs"]; //} }



