Trying to figure out a general to-go way for JSON value parsing.
No error checking:
myField = jsonValue["myField"].as_string();`
With error checking:
if (jsonValue.is_null()) return false; if (!jsonValue.is_object()) return false; for (auto it = jsonValue.as_object().cbegin(); it != jsonValue.as_object().cend(); ++it) { const std::string& str = it->first; const json::value& v = it->second; if (str == "myField") { if (v.is_string()) { myField = v.as_string(); continue; } else { return false; } } }
The difference in amount of code is noticeable. Should I bother with error checking or the first approach would be enough?