iguana
iguana copied to clipboard
Could not represent null fields...
#include <iostream>
#include "iguana/json.hpp"
struct Model {
std::string str;
int num;
};
REFLECTION (Model, str, num);
void parseJson (const char *json)
{
Model model;
model.str = "";
model.num = 0;
iguana::json::from_json (model, json);
std::cout << "str: '" << model.str << "', "
<< "num: " << model.num << std::endl;
}
//$ clang++ json_test.cpp -std=c++14 -o json_test && ./json_test
int main (int argc, char *argv[])
{
parseJson (R"({ "str": "string", "num": 6, "dummy": 0 })"); // str: 'string', num: 6
parseJson (R"({ "str": "string", "num": 6 })"); // str: 'string', num: 6
parseJson (R"({ "str": "string" })"); // str: 'string', num: 0
parseJson (R"({ "dummy": 0 })"); // str: '', num: 0
parseJson (R"({ "dummy": 0, "num": 6 })"); // str: '', num: 0
parseJson (R"({ "dummy": 0, "num": 6, "str": "string" })"); // str: '', num: 0
return 0;
}
- Unable to tell if a field presents or not..
- Failed to parse
json
with some dummy field...