mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
AK: Add get_or() method to JsonObject
This allows to retrieve a default value for items thare are not available in the json object.
This commit is contained in:
parent
5f579904c1
commit
45921328e4
1 changed files with 6 additions and 0 deletions
|
@ -72,6 +72,12 @@ public:
|
||||||
return value ? *value : JsonValue(JsonValue::Type::Undefined);
|
return value ? *value : JsonValue(JsonValue::Type::Undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonValue get_or(const String& key, JsonValue alternative) const
|
||||||
|
{
|
||||||
|
auto* value = get_ptr(key);
|
||||||
|
return value ? *value : alternative;
|
||||||
|
}
|
||||||
|
|
||||||
const JsonValue* get_ptr(const String& key) const
|
const JsonValue* get_ptr(const String& key) const
|
||||||
{
|
{
|
||||||
auto it = m_members.find(key);
|
auto it = m_members.find(key);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue