jsoncpp icon indicating copy to clipboard operation
jsoncpp copied to clipboard

how std::string and a Json::Value string convert, each other?

Open xinsuinizhuan opened this issue 1 year ago • 1 comments

I read a json string,and convert to a Json::Value: void xxx_json_param(const char* _jsondata, const char* _savepath) { Json::Value root; Json::Reader reader; reader.parse((const std::string)_jsondata, root);

    Json::Value applicationjson_j = root["Application"];
    //applicationjson_j  is also a json,but when i asString(), it broke 
    string applicationjson = root["Application"].asString();

}

图片

xinsuinizhuan avatar Feb 26 '24 07:02 xinsuinizhuan

@xinsuinizhuan,

in this example, the Application json value is an object. In the case of an object or an array the asString method throws an exception and aborts the application execution. Object and Array are not convertible to string.

daudrain avatar Dec 01 '24 20:12 daudrain