mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-15 19:42:12 +02:00
Extracted JsonNodeSerializer
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
#include "JsonValue.h"
|
||||
#include "JsonNode.h"
|
||||
#include "StringBuilder.h"
|
||||
#include "JsonNodeSerializer.h"
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
@ -99,45 +100,6 @@ size_t JsonObject::printTo(char* buffer, size_t bufferSize) const
|
||||
|
||||
size_t JsonObject::printTo(Print& p) const
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
n += p.write('{');
|
||||
|
||||
JsonNode* firstChild = _node->content.asObject.child;
|
||||
|
||||
for (JsonNode* child = firstChild; child; child = child->next)
|
||||
{
|
||||
const char* childKey = child->content.asKey.key;
|
||||
JsonNode* childValue = child->content.asKey.value;
|
||||
|
||||
n += EscapedString::printTo(childKey, p);
|
||||
n += p.write(':');
|
||||
|
||||
switch (childValue->type)
|
||||
{
|
||||
case JSON_STRING:
|
||||
n += EscapedString::printTo(childValue->content.asString, p);
|
||||
break;
|
||||
|
||||
case JSON_INTEGER:
|
||||
n += p.print(childValue->content.asInteger);
|
||||
break;
|
||||
|
||||
case JSON_BOOLEAN:
|
||||
n += p.print(childValue->content.asBoolean ? "true" : "false");
|
||||
break;
|
||||
}
|
||||
|
||||
if (childValue->type >= JSON_DOUBLE_0_DECIMALS)
|
||||
n += p.print(childValue->content.asDouble, childValue->type - JSON_DOUBLE_0_DECIMALS);
|
||||
|
||||
if (child->next)
|
||||
{
|
||||
n += p.write(',');
|
||||
}
|
||||
}
|
||||
|
||||
n += p.write('}');
|
||||
|
||||
return n;
|
||||
JsonNodeSerializer serializer(p);
|
||||
return serializer.serialize(_node);
|
||||
}
|
Reference in New Issue
Block a user