简体   繁体   English

boost property_tree :: json_parser :: read_json&iostreams :: filtering_streambuf

[英]boost property_tree::json_parser::read_json & iostreams::filtering_streambuf

Im trying to read deflated json and experiencing type conversion problems, here is the code 我试图阅读放气的json并遇到类型转换问题,这里是代码

boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
std::istringstream iss(std::ios::binary);
iss.rdbuf()->pubsetbuf(buf, len);
iss.imbue( std::locale("ru_RU.CP1251") );
in.push( boost::iostreams::zlib_decompressor() );
in.push( iss );

boost::property_tree::ptree pt;
boost::property_tree::json_parser::read_json(in, pt); // <-- Compile error

Compiler says: 编译说:

src/ABPacking.cpp:48: error: no matching function for call to 'read_json(boost::iostreams::filtering_streambuf, std::allocator, boost::iostreams::public_>&, boost::property_tree::ptree&)' src / ABPacking.cpp:48:错误:没有匹配函数来调用'read_json(boost :: iostreams :: filtering_streambuf,std :: allocator,boost :: iostreams :: public _>&,boost :: property_tree :: ptree&) “

The question is how to pass filtering_streambuf to read_json without unnecessary data copying? 问题是如何在不进行不必要的数据复制的情况下将filtering_streambuf传递给read_json

read_json expects either a file name or a stream with the JSON content. read_json需要文件名或具有JSON内容的 You're trying to pass a stream buffer , and it won't know what to do with it. 您正在尝试传递流缓冲区 ,它不知道如何处理它。

As a solution, just pass the stream buffer to an istream that consumes it and pass that to read_json : 作为解决方案,只需将流缓冲区传递给使用它的istream并将其传递给read_json

std::istream input(&in_buf);
read_json(input, pt);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM