C++ json
一、环境安装
sudo apt update
sudo apt install nlohmann-json3-dev
二、使用样例
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main() {
json j;
j["name"] = "John Doe";
j["age"] = 30;
j["is_student"] = false;
j["courses"] = {"math", "english", "history"};
std::string json_string = j.dump(4);
std::cout << json_string << std::endl;
std::string keyToFind = "key2";
if (j.find(keyToFind) != j.end()) {
std::cout << "Key found: " << keyToFind << std::endl;
} else {
std::cout << "Key not found: " << keyToFind << std::endl;
return 0;
}