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\n";  
        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;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM