Files
ArduinoJson/src/JsonArray.cpp

54 lines
1.2 KiB
C++
Raw Normal View History

2015-02-07 16:05:48 +01:00
// Copyright Benoit Blanchon 2014-2015
2014-10-23 23:39:22 +02:00
// MIT License
//
// Arduino JSON library
// https://github.com/bblanchon/ArduinoJson
2014-11-03 18:35:22 +01:00
#include "../include/ArduinoJson/JsonArray.hpp"
2014-10-29 14:24:34 +01:00
2014-11-03 18:35:22 +01:00
#include "../include/ArduinoJson/JsonBuffer.hpp"
#include "../include/ArduinoJson/JsonObject.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-30 14:03:33 +01:00
JsonArray JsonArray::_invalid(NULL);
JsonArray::node_type *JsonArray::getNodeAt(size_t index) const {
node_type *node = _firstNode;
while (node && index--) node = node->next;
return node;
2014-10-29 14:24:34 +01:00
}
JsonArray &JsonArray::createNestedArray() {
if (!_buffer) return JsonArray::invalid();
JsonArray &array = _buffer->createArray();
add(array);
return array;
2014-10-16 16:25:42 +02:00
}
2014-10-29 14:24:34 +01:00
JsonObject &JsonArray::createNestedObject() {
if (!_buffer) return JsonObject::invalid();
JsonObject &object = _buffer->createObject();
add(object);
return object;
2014-10-16 16:25:42 +02:00
}
void JsonArray::removeAt(size_t index) { removeNode(getNodeAt(index)); }
void JsonArray::writeTo(JsonWriter &writer) const {
writer.beginArray();
2014-10-29 14:24:34 +01:00
const node_type *child = _firstNode;
while (child) {
child->content.writeTo(writer);
2014-10-29 14:24:34 +01:00
child = child->next;
if (!child) break;
2014-10-29 14:24:34 +01:00
writer.writeComma();
2014-10-29 14:24:34 +01:00
}
writer.endArray();
2014-10-29 14:24:34 +01:00
}