zoukankan      html  css  js  c++  java
  • error C4996: ‘Json::Reader::Char’: Use CharReader and CharReaderBuilder instead

    1、编译下面代码时,遇到标题中的错误

    const char* str = "{"name":"xiaoming","age":18}";  
        Json::Value root;  
        Json::Reader reader;  
        if (!reader.parse(str, root))  
        {  
            cout << "Parse from str failed
    ";  
            return;  
        }  
          
        string name = root["name"].asCString();  
        int age = root["age"].asInt();  
        std::cout << "name: " << name << "  age:" << age;  

    2、解决方法,根据提示修改代码,如下:

        Json::CharReaderBuilder b;
        Json::CharReader* reader(b.newCharReader());
        Json::Value root;
        JSONCPP_STRING errs;
        bool ok = reader->parse(str, str + std::strlen(str), &root, &errs);
        if (ok&&errs.size() == 0)
        {
            std::string upload_id = root["uploadid"].asString();  // 访问节点,upload_id = "UP000000"  
            int code = root["code"].asInt();    // 访问节点,code = 100  
        }
        delete reader;
  • 相关阅读:
    软件测试:Homework 3
    软件测试:Lab 1
    软件测试:Homework 2
    软件测试:Homework 1
    JAVA的回忆
    Java 操作符
    Java 笔录
    经典C#编程理解,概要,经典
    网络精灵
    签到计时
  • 原文地址:https://www.cnblogs.com/happykoukou/p/7987268.html
Copyright © 2011-2022 走看看