mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
04a8fc9bd7
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.
21 lines
528 B
C++
21 lines
528 B
C++
#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();
|
|
}
|