Hey, i have such code
std::vector<ConfigStructures::MyConfigs> MyConfigs;
json JsonData;
struct MyConfigs
{
bool selected = false;
std::string Name;
};
inline void to_json(json& j, const MyConfigs& config) {
j = json{
{ "selected", config.selected },
{ "name", config.Name }
};
}
inline void from_json(const json& j, MyConfigs& config) {
config.selected = j.at("selected").get < bool >();
config.Name = j.at("name").get < int >();
}
i can serialize to json, as i set to_json function
JsonData = MyConfigs;
But i can't do this
MyConfigs = JsonData
Try do like this:
MyConfigs = JsonData.get < vector<ConfigStructures::MyConfigs> >();
and this
MyConfigs.clear();
for (auto& element : JsonData) {
MyConfigs.push_back(element);
}
But it give me error:
JSON_THROW(type_error::create(302, "type must be number, but is " + j.type_name()));
Does it work now?