在创建工程时,选择使用静态库
1、在Stdafx.h中加载
#pragma comment(lib,"json.lib")
2、将json下的include\json目录复制到工程目录中
3、在工程头文件中加载json头文件
#include "json/json.h"
CString plugclass::GetValue(CString json , CString action)
{
USES_CONVERSION;
std::string strValue =W2A(json);
Json::Reader reader;
Json::Value json_object;
if (reader.parse(strValue, json_object))
{
return (CString)json_object[W2A(action.GetBuffer(0))].asString().c_str();
} else {
return L"";
}
}
调用方法
CString str("{"Action":"Login","UserName":"user","Passwd":"pass"}");
CString strjson = GetValue(str,L"Action");
AfxMessageBox(strjson);
返回结果:
Login