summaryrefslogtreecommitdiff
path: root/AK/JsonObject.h
diff options
context:
space:
mode:
Diffstat (limited to 'AK/JsonObject.h')
-rw-r--r--AK/JsonObject.h27
1 files changed, 17 insertions, 10 deletions
diff --git a/AK/JsonObject.h b/AK/JsonObject.h
index 5b95005495..aa177da18d 100644
--- a/AK/JsonObject.h
+++ b/AK/JsonObject.h
@@ -41,26 +41,32 @@ public:
~JsonObject() {}
JsonObject(const JsonObject& other)
- : m_members(other.m_members)
+ : m_order(other.m_order)
+ , m_members(other.m_members)
{
}
JsonObject(JsonObject&& other)
- : m_members(move(other.m_members))
+ : m_order(move(other.m_order))
+ , m_members(move(other.m_members))
{
}
JsonObject& operator=(const JsonObject& other)
{
- if (this != &other)
+ if (this != &other) {
m_members = other.m_members;
+ m_order = other.m_order;
+ }
return *this;
}
JsonObject& operator=(JsonObject&& other)
{
- if (this != &other)
+ if (this != &other) {
m_members = move(other.m_members);
+ m_order = move(other.m_order);
+ }
return *this;
}
@@ -70,7 +76,7 @@ public:
JsonValue get(const String& key) const
{
auto* value = get_ptr(key);
- return value ? *value : JsonValue(JsonValue::Type::Undefined);
+ return value ? *value : JsonValue(JsonValue::Type::Null);
}
JsonValue get_or(const String& key, JsonValue alternative) const
@@ -94,14 +100,17 @@ public:
void set(const String& key, JsonValue value)
{
+ m_order.append(key);
m_members.set(key, move(value));
}
template<typename Callback>
void for_each_member(Callback callback) const
{
- for (auto& it : m_members)
- callback(it.key, it.value);
+ for (size_t i = 0; i < m_order.size(); ++i) {
+ auto property = m_order[i];
+ callback(property, m_members.get(property).value());
+ }
}
template<typename Builder>
@@ -113,6 +122,7 @@ public:
String to_string() const { return serialized<StringBuilder>(); }
private:
+ Vector<String> m_order;
HashMap<String, JsonValue> m_members;
};
@@ -193,9 +203,6 @@ inline void JsonValue::serialize(Builder& builder) const
case Type::UnsignedInt64:
builder.appendf("%llu", as_u64());
break;
- case Type::Undefined:
- builder.append("undefined");
- break;
case Type::Null:
builder.append("null");
break;