2016-01-07 22:35:12 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2016
|
2014-10-23 23:39:22 +02:00
|
|
|
// MIT License
|
|
|
|
//
|
|
|
|
// Arduino JSON library
|
|
|
|
// https://github.com/bblanchon/ArduinoJson
|
2016-01-07 22:35:12 +01:00
|
|
|
// If you like this project, please add a star!
|
2014-10-23 23:39:22 +02:00
|
|
|
|
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);
|
|
|
|
|
2015-05-23 15:32:50 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-05-23 15:32:50 +02:00
|
|
|
void JsonArray::removeAt(size_t index) { removeNode(getNodeAt(index)); }
|
2015-05-02 15:16:18 +02:00
|
|
|
|
2014-11-08 19:40:07 +01:00
|
|
|
void JsonArray::writeTo(JsonWriter &writer) const {
|
2014-11-09 13:54:03 +01:00
|
|
|
writer.beginArray();
|
2014-10-29 14:24:34 +01:00
|
|
|
|
2014-11-09 13:54:03 +01:00
|
|
|
const node_type *child = _firstNode;
|
|
|
|
while (child) {
|
|
|
|
child->content.writeTo(writer);
|
2014-10-29 14:24:34 +01:00
|
|
|
|
2014-11-09 13:54:03 +01:00
|
|
|
child = child->next;
|
|
|
|
if (!child) break;
|
2014-10-29 14:24:34 +01:00
|
|
|
|
2014-11-09 13:54:03 +01:00
|
|
|
writer.writeComma();
|
2014-10-29 14:24:34 +01:00
|
|
|
}
|
2014-11-09 13:54:03 +01:00
|
|
|
|
|
|
|
writer.endArray();
|
2014-10-29 14:24:34 +01:00
|
|
|
}
|