enum class Type
{
TOP =0,
LOW =1,
};
struct Info
{
std::string Animated;
int Age;
Type type;
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Info, Animated, age)
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Info, Animated, Age,type)
};
int main(int argc, char *argv[])
{
std::vector<Info>vess{ {"11",1,static_cast<Type>(0)},{"222",3,static_cast<Type>(1)}};
nlohmann::json js(vess);
std::string str11 = js.dump(2);
std::string pathToFile = "C:/Users/dell/Desktop/B&B5.0multi Bridge/StateType11.json";
ifstream streamOfFile(pathToFile);
if (nlohmann::json::accept(streamOfFile)) {
cout << "Nothing to complain about!" << endl;
}
else {
cout << "JSON NOT VALID!" << endl;
}
streamOfFile.clear();
streamOfFile.seekg(0, ios::beg);
try
{
auto json = nlohmann::json::parse(streamOfFile);
auto iterFind = json.find("Image");
if (iterFind == json.end()){
return 0;
}
auto subJson = json.at("Image");
auto AnimatedStr = subJson.value("Animated",true);
std::vector<Info>info;
auto vec = subJson.at("IDs");
auto vess = vec.get<std::vector<Info>>();
//for (auto &info2:vec)
//{
// nlohmann::json j = info2;
// auto info = j.get<Info>();
// int s;
//}
//
//auto vess = vec.get<std::vector<Info>>;
}
catch (const std::exception& e)
{
std::cout << e.what();
}
}