boostorg / property_tree

Boost.org property_tree module
http://boost.org/libs/property_tree
55 stars 92 forks source link

Why does read_json(..) throw exception for utf-8 stringstream from string? #68

Closed dkd1111 closed 3 years ago

dkd1111 commented 3 years ago
/*CODE_1*/
boost::beast::http::response<boost::beast::http::string_body> &&res
...
std::stringstream ss;
ss << res.body();
boost::property_tree::ptree tree{};
boost::property_tree::read_json(ss, tree);

CODE_1 is fine.

/*CODE_2*/
boost::beast::http::response<boost::beast::http::string_body> &&res
...
std::stringstream ss;
ss << res.body();
std::string msg;
msg << ss.str();
ss.clear();
ss << msg;
boost::property_tree::ptree tree{};
boost::property_tree::read_json(ss, tree);

CODE_2 throws exception("garbage after data").

Variable "ss" is encoded utf-8. Why does read_json(..) throw exception for utf-8 stringstream from string?