前端之家收集整理的这篇文章主要介绍了
Jsoncpp的简单使用,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#include<iostream>
struct SystemDate{
int nYear;
int nMonth;
int nDay;
}
void getJsonData(SystemDate &pCurDate)
{
Json::CharReaderBuilder jsonBuilder;
Json::Value root;
unique_ptr<Json::CharReader> const reader(jsonBuilder.newCharReader());
std::string strTime = "{\"Year\":2018,\"Month\":3,\"Day\":7}";
jsonBuilder["colloectComments"] = false;
JSONCPP_STRING errs;
if (!reader->parse(strTime.c_str(),strTime.data() + strTime.size(),&root,&errs))
{
pCurDate.nYear = 0;
pCurDate.nMonth = 0;
pCurDate.nDay = 0;
return;
}
cout << root << endl;
pCurDate.nYear = root["Year"].asInt();
pCurDate.nMonth = root["Month"].asInt();
pCurDate.nDay = root["Day"].asInt();
}
int main()
{
SystemDate date;
getJsonDate(date);
cout << date << endl;
}
原文链接:https://www.f2er.com/json/288606.html