Boost write_json property incorrect behavior

I am encoding a JSON wrapper for a Boost property tree. Currently, the focus is on writing the resulting JSON to a string or file.

Using boost :: property_tree :: json_parser :: write_json (ss, * pt), the resulting property tree is written to the string.

But this method does not understand what is true, false, zero or number. Everything is converted to a string.

Reading Boost documentation is a limitation of the library. Is there any way to change this behavior?

+4
source share
1 answer

Link This link fixes a problem.

This is due to a change in the promotion code, because of this I tried another alternative. My solution includes regular expressions:

std::string JSONObject::toString() const { boost::regex exp("\"(null|true|false|[0-9]+(\\.[0-9]+)?)\""); std::stringstream ss; boost::property_tree::json_parser::write_json(ss, *pt); std::string rv = boost::regex_replace(ss.str(), exp, "$1"); return rv; } 

I am mainly looking for keywords: true, false, null and any type of number. Matches are replaced with the same without quotes.

+11
source

Source: https://habr.com/ru/post/1447101/


All Articles