-
Just as the title, server give me a JSON string maybe a value like: My C++ struct : NLOHMANN_DEFINE_TYPE_INTRUSIVE(LabelItem, label); when I parse data from server: My program crashed!
error is : Can anyone help me? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Beta Was this translation helpful? Give feedback.
I'm not sure why it doesn't pick up the
from_json
in theJsonString
for theSubPublisherItem
, but I wasn't suggesting you create a wrapper type forstd::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 useNLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE
to do theto_json
part.Having said that, using
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT
in the containing classes works once you add a default constructor toJsonString
. https://www.godbolt.org/z/W61P8jfeE