DNSBackend::KeyData key;
key.id = intFromJson(jsonKey, "id");
key.flags = intFromJson(jsonKey, "flags");
- key.active = boolFromJson(jsonKey, "active");
+ key.active = asBool(jsonKey["active"]);
key.content = stringFromJson(jsonKey, "content");
keys.push_back(key);
}
if (value.is_string()) return value.string_value();
throw JsonException("Json value not convertible to String");
};
+
+ bool asBool(const Json& value) {
+ if (value.is_bool()) return value.bool_value();
+ try {
+ string val = asString(value);
+ if (val == "0") return false;
+ if (val == "1") return true;
+ } catch (JsonException) {};
+ throw JsonException("Json value not convertible to boolean");
+ };
};
#endif
auto val = container[key];
if (val.is_bool()) {
return val.bool_value();
- } else if (val.is_number()) {
- if (val.int_value() == 1) return true;
- else if (val.int_value() == 0) return false;
}
throw JsonException("Key '" + string(key) + "' not present or not a Bool");
}
auto val = container[key];
if (val.is_bool()) {
return val.bool_value();
- } else if (val.is_number()) {
- if (val.int_value() == 1) return true;
- else if (val.int_value() == 0) return false;
}
return default_value;
}