mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-24 07:47:32 +02:00
Test JsonObject::prettyPrintTo()
This commit is contained in:
@ -16,14 +16,12 @@ public:
|
||||
virtual void beginArray()
|
||||
{
|
||||
_length += _sink.write('[');
|
||||
_indenter.indent();
|
||||
_length += _indenter.println();
|
||||
indent();
|
||||
}
|
||||
|
||||
virtual void endArray()
|
||||
{
|
||||
_length += _indenter.println();
|
||||
_indenter.unindent();
|
||||
unindent();
|
||||
_length += _sink.write(']');
|
||||
}
|
||||
|
||||
@ -41,14 +39,27 @@ public:
|
||||
virtual void beginObject()
|
||||
{
|
||||
_length += _sink.write('{');
|
||||
indent();
|
||||
}
|
||||
|
||||
virtual void endObject()
|
||||
{
|
||||
unindent();
|
||||
_length += _sink.write('}');
|
||||
_indenter.unindent();
|
||||
}
|
||||
|
||||
private:
|
||||
IndentedPrint& _indenter;
|
||||
|
||||
void indent()
|
||||
{
|
||||
_indenter.indent();
|
||||
_length += _indenter.println();
|
||||
}
|
||||
|
||||
void unindent()
|
||||
{
|
||||
_length += _indenter.println();
|
||||
_indenter.unindent();
|
||||
}
|
||||
};
|
||||
|
@ -57,7 +57,6 @@ protected:
|
||||
|
||||
bool checkNodeType(JsonNodeType expectedType);
|
||||
|
||||
private:
|
||||
JsonNode* _node;
|
||||
};
|
||||
|
||||
|
@ -33,6 +33,20 @@ void JsonObject::remove(char const* key)
|
||||
}
|
||||
}
|
||||
|
||||
JsonObject JsonObject::createNestedObject(char const* key)
|
||||
{
|
||||
JsonNode* node = getOrCreateNodeAt(key);
|
||||
|
||||
if (node)
|
||||
{
|
||||
node->type = JSON_OBJECT;
|
||||
node->content.asContainer.child = 0;
|
||||
node->content.asContainer.buffer = _node->content.asContainer.buffer;
|
||||
}
|
||||
|
||||
return JsonObject(node);
|
||||
}
|
||||
|
||||
JsonNode* JsonObject::getOrCreateNodeAt(const char* key)
|
||||
{
|
||||
if (!checkNodeType(JSON_OBJECT)) return 0;
|
||||
|
@ -8,6 +8,7 @@ struct JsonNode;
|
||||
class JsonObject : public JsonContainer
|
||||
{
|
||||
public:
|
||||
|
||||
JsonObject()
|
||||
{
|
||||
}
|
||||
@ -20,6 +21,8 @@ public:
|
||||
JsonValue operator[](const char* key);
|
||||
void remove(const char* key);
|
||||
|
||||
JsonObject createNestedObject(const char* key);
|
||||
|
||||
private:
|
||||
JsonNode* getOrCreateNodeAt(char const* key);
|
||||
};
|
Reference in New Issue
Block a user