[C++]jsoncpp中将整个Json::Value转成std::string或者把里面值转成string类型

Posted FL1623863129

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[C++]jsoncpp中将整个Json::Value转成std::string或者把里面值转成string类型相关的知识,希望对你有一定的参考价值。

把键值对中的值转成string类型

注意asString后类型是Json::String并不是std::string

Json::Value rootJsonValue;
rootJsonValue["foo"] = "bar";
std::string s = rootJsonValue["foo"].asString();
std::cout << s << std::endl; // bar

把整个Json::Value转成string

std::string JsonAsString(const Json::Value &json)

    std::string result;
    Json::StreamWriterBuilder wbuilder;

    wbuilder["indentation"] = "";       // Optional
    result = Json::writeString(wbuilder, json);
    return result;

以上是关于[C++]jsoncpp中将整个Json::Value转成std::string或者把里面值转成string类型的主要内容,如果未能解决你的问题,请参考以下文章

C++ 解析Json——jsoncpp

C++ jsoncpp解析二维数组

Linux(程序设计):31---jsoncpp库(C++操作JSON)

在C++环境中使用JsonCpp读写Json数据

如何将 Python 绑定到包含 Jsoncpp 的 C++ 代码?

Linux(程序设计):31---jsoncpp库(C++操作JSON)