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

查看:59
本文介绍了boost property_tree::json_parser::read_json &iostreams::filtering_streambuf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试读取压缩的 json 并遇到类型转换问题,这是代码

Im trying to read deflated json and experiencing type conversion problems, here is the code

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

编译器说:

src/ABPacking.cpp:48: 错误:没有匹配的函数调用‘read_json(boost::iostreams::filtering_streambuf, std::allocator,boost::iostreams::public_>&, boost::property_tree::ptree&)’

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&)’

问题是如何将 filtering_streambuf 传递给 read_json 而不进行不必要的数据复制?

The question is how to pass filtering_streambuf to read_json without unnecessary data copying?

推荐答案

read_json 需要包含 JSON 内容的文件名或 .您正在尝试传递一个流缓冲区,但它不知道如何处理它.

read_json expects either a file name or a stream with the JSON content. You're trying to pass a stream buffer, and it won't know what to do with it.

作为解决方案,只需将流缓冲区传递给使用它的 istream 并将其传递给 read_json:

As a solution, just pass the stream buffer to an istream that consumes it and pass that to read_json:

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

这篇关于boost property_tree::json_parser::read_json &amp;amp;iostreams::filtering_streambuf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆