mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:34:57 +00:00
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.
This commit is contained in:
parent
7ccb84e58e
commit
04a8fc9bd7
7 changed files with 301 additions and 0 deletions
21
AK/JsonObject.cpp
Normal file
21
AK/JsonObject.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <AK/JsonObject.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
|
||||
String JsonObject::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
int index = 0;
|
||||
builder.append('{');
|
||||
for_each_member([&] (auto& key, auto& value) {
|
||||
builder.append('"');
|
||||
builder.append(key);
|
||||
builder.append('"');
|
||||
builder.append(':');
|
||||
builder.append(value.to_string());
|
||||
if (index != size() - 1)
|
||||
builder.append(',');
|
||||
++index;
|
||||
});
|
||||
builder.append('}');
|
||||
return builder.to_string();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue