I have simple C++ code that uses Boost library:
auto jsonStringPtr = jsonValuePtr->if_string();
How can I convert this value to std::string without quotes?
I tested this code:
std::string myString = boost::json::serialize(*jsonStringPtr);
but it contains quotes e.g. "abc" insted of abc... Any idea?
#edit
Example:
boost::json::error_code errorCode;
boost::json::value jsonValue = boost::json::parse("{\"fff\": \"abc\"}", errorCode);
auto jsonString = jsonValue.as_object()["fff"].as_string();
std::string myString = boost::json::serialize(jsonString);
I found the solution:
boost::json::value_to<std::string>(jsonValue)
auto jsonStringPtr = jsonValuePtr->as_string().c_str();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With