json字符串转为json对象

    Json::Value root;
    Json::Reader reader;
    reader.parse(str, root);
    
    cout << root << endl;

    //操作json对象

    for (auto value : root)
    {
        if (value.type() == Json::ValueType::stringValue)
        {
            cout << value.asString() << endl;
        }
        else if (value.type() == Json::ValueType::intValue)
        {
            cout << value.asInt() << endl;
        }
        else if (value.type() == Json::ValueType::objectValue)
        {
            //里面嵌套的是json对象,这里就不分析了
        }
        
    }    

 

posted @ 2021-01-06 21:50  zwj鹿港小镇  阅读(112)  评论(0编辑  收藏  举报