加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Jsoncpp的简单使用

发布时间:2020-12-16 19:46:47 所属栏目:百科 来源:网络整理
导读:直接上代码 #includeiostream struct SystemDate{ int nYear; int nMonth; int nDay;} void getJsonData(SystemDate pCurDate){ Json::CharReaderBuilder jsonBuilder; Json::Value root; unique_ptrJson::CharReader const reader(jsonBuilder.newCharReade

直接上代码

#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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读