mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 20:42:24 +02:00
53 lines
1.0 KiB
C++
53 lines
1.0 KiB
C++
// Copyright Benoit Blanchon 2014
|
|
// MIT License
|
|
//
|
|
// Arduino JSON library
|
|
// https://github.com/bblanchon/ArduinoJson
|
|
|
|
#include "ArduinoJson/JsonArray.hpp"
|
|
#include "ArduinoJson/JsonObject.hpp"
|
|
#include "ArduinoJson/JsonValue.hpp"
|
|
|
|
using namespace ArduinoJson;
|
|
using namespace ArduinoJson::Internals;
|
|
|
|
JsonValueImpl *JsonArray::operator[](int index) const {
|
|
for (const_iterator it = begin(); it != end(); ++it) {
|
|
if (!index) return *it;
|
|
index--;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
JsonValueImpl *JsonArray::add() {
|
|
if (_buffer) return NULL;
|
|
|
|
JsonArrayNode *node = _buffer->create<JsonArrayNode>();
|
|
if (!node) return NULL;
|
|
|
|
return &node.value;
|
|
}
|
|
|
|
JsonArrayImpl *JsonArray::createNestedArray() {
|
|
JsonNode *node = createNode();
|
|
|
|
if (node) {
|
|
node->setAsArray(_node->getContainerBuffer());
|
|
addChild(node);
|
|
}
|
|
|
|
return JsonArray(node);
|
|
}
|
|
|
|
JsonObject JsonArray::createNestedObject() {
|
|
JsonNode *node = createNode();
|
|
|
|
if (node) {
|
|
node->setAsObject(_node->getContainerBuffer());
|
|
addChild(node);
|
|
}
|
|
|
|
return JsonObject(node);
|
|
}
|