jsoncpp修改;解决自动格式化

更多方法参考:https://abraverman.gitee.io/2020/05/12/json-cpp/

      //json_value.cpp文件

	//原有的
	String Value::toStyledString() const
	{
		StreamWriterBuilder builder;
		builder["emitUTF8"] = true;		//新添加的-输出中文 而非unicode
		String out = this->hasComment(commentBefore) ? "\n" : "";
		out += Json::writeString(builder, *this);
		out += '\n';

		return out;
	}

	//新添加
	Json::String Value::toRawString() const
	{
		StreamWriterBuilder builder;
		builder["commentStyle"] = "None";
		builder["indentation"] = "";
		builder["emitUTF8"] = true;
		String out = Json::writeString(builder, *this);
		return out;
	}
	bool Value::parse(std::string_view str)
	{
		Json::CharReaderBuilder builder;
		const std::unique_ptr reader(builder.newCharReader());
		Json::Value root;
		std::string err;
		return reader->parse(str.data(), str.data()+str.size(),this,&err);
	}

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注