直接上代码
#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;
//将字符串写入到json变量中
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.jb51.cc/json/288606.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。