下载
jsoncpp下载位置:
GitHub - open-source-parsers/jsoncpp: A C++ library for interacting with JSON.
编译库
生成的库文件位置如下
管理库和头文件
配置visual studio
使用jsoncpp
#include <iostream>
#include <json/json.h>
#include <json/value.h>
#include <json/reader.h>
int main()
{
//std::cout << "Hello World!\n";
Json::Value root;
root["id"] = 1001;
root["data"] = "hello world";
std::string request = root.toStyledString();
std::cout << "request is " << request << std::endl;
Json::Value root2;
Json::Reader reader;
reader.parse(request, root2);
std::cout << "msg id is " << root2["id"] << " msg is " << root2["data"] << std::endl;
}
运行效果如下: