Files
ArduinoJson/src/JsonArray.cpp

50 lines
1013 B
C++
Raw Normal View History

2014-10-23 23:39:22 +02:00
// 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"
2014-10-16 16:25:42 +02:00
2014-10-18 23:05:54 +02:00
using namespace ArduinoJson;
using namespace ArduinoJson::Internals;
2014-10-23 19:54:00 +02:00
JsonValue JsonArray::operator[](int index) const {
2014-10-24 18:31:50 +02:00
for (const_iterator it = begin(); it != end(); ++it) {
if (!index) return *it;
2014-10-23 19:54:00 +02:00
index--;
}
return JsonValue();
2014-10-16 16:25:42 +02:00
}
2014-10-25 21:02:13 +02:00
JsonValue JsonArray::addNewValue() {
2014-10-23 19:54:00 +02:00
JsonNode *node = createNode();
2014-10-25 21:02:13 +02:00
if (node) addChild(node);
return JsonValueInternal(node);
2014-10-16 16:25:42 +02:00
}
2014-10-23 19:54:00 +02:00
JsonArray JsonArray::createNestedArray() {
JsonNode *node = createNode();
if (node) {
node->setAsArray(_node->getContainerBuffer());
addChild(node);
}
return JsonArray(node);
2014-10-16 16:25:42 +02:00
}
2014-10-23 19:54:00 +02:00
JsonObject JsonArray::createNestedObject() {
JsonNode *node = createNode();
if (node) {
node->setAsObject(_node->getContainerBuffer());
addChild(node);
}
return JsonObject(node);
2014-10-22 17:59:59 +02:00
}