1.去github下载jsonCpp
2.下载之后如图
3.执行python 脚本生成dist文件
4.将dist导入到c++项目中使用
5.具体使用方法
#include "json/json.h"
#include "json-forwards.h"
using namespace std;
Json::Value json;
Json::CharReaderBuilder builder;
std::stringstream stream(strData);
std::string errs;
if (!Json::parseFromStream(builder, stream, &json, &errs)) {
AfxMessageBox(_T("解析错误"));
}else {
std::string rescode = json.get("rescode", "UTF-8").asString();
std::string msg = json.get("msg", "UTF-8").asString();
std::cout << rescode << std::endl;
if (rescode == "200") {
const Json::Value dataDic = json["data"];
std::string liveIdTmp = dataDic.get("liveId", "UTF-8").asString();
std::cout << liveIdTmp << std::endl;
}else {
CString tipsStr;
tipsStr = msg.c_str();
AfxMessageBox(tipsStr);
}
}
6.如果有帮助请大家点赞哦!
来源:CSDN
作者:隐藏的Bug
链接:https://blog.csdn.net/oZhaiHenZhai/article/details/104606131