Skip to content

How to parse a possibly null json string in C++! need help!!!!!!!!! #4240

Answered by gregmarr
aijyo asked this question in Q&A
Discussion options

You must be logged in to vote

I'm not sure why it doesn't pick up the from_json in the JsonString for the SubPublisherItem, but I wasn't suggesting you create a wrapper type for std::string. I was suggesting that you implement the from_json in the container classes, as the method you're trying won't handle a missing value. With the latest version you can use NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE to do the to_json part.

Having said that, using NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT in the containing classes works once you add a default constructor to JsonString. https://www.godbolt.org/z/W61P8jfeE

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@aijyo
Comment options

@gregmarr
Comment options

Answer selected by aijyo
@aijyo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants