diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-06-17 19:47:35 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-06-17 19:47:35 +0200 |
commit | 04a8fc9bd7d4a3dd31cce39266464bb05ca0bfca (patch) | |
tree | d0e7d113138caffe0f56ef19b4814193cc4cc3ec /AK/JsonArray.h | |
parent | 7ccb84e58efd4b48ec51150a5d8495bad71bbfbc (diff) | |
download | serenity-04a8fc9bd7d4a3dd31cce39266464bb05ca0bfca.zip |
AK: Add some classes for JSON encoding.
This patch adds JsonValue, JsonObject and JsonArray. You can use them to
build up a JsonObject and then serialize it to a string via to_string().
This patch only implements encoding, no decoding yet.
Diffstat (limited to 'AK/JsonArray.h')
-rw-r--r-- | AK/JsonArray.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/AK/JsonArray.h b/AK/JsonArray.h new file mode 100644 index 0000000000..38eaad09c6 --- /dev/null +++ b/AK/JsonArray.h @@ -0,0 +1,24 @@ +#pragma once + +#include <AK/JsonValue.h> +#include <AK/Vector.h> + +class JsonArray { +public: + JsonArray() {} + ~JsonArray() {} + + int size() const { return m_values.size(); } + bool is_empty() const { return m_values.is_empty(); } + + const JsonValue& at(int index) const { return m_values.at(index); } + const JsonValue& operator[](int index) const { return at(index); } + + void clear() { m_values.clear(); } + void append(const JsonValue& value) { m_values.append(value); } + + String to_string() const; + +private: + Vector<JsonValue> m_values; +}; |