-
Notifications
You must be signed in to change notification settings - Fork 0
/
JsonArray.cpp
executable file
·60 lines (45 loc) · 1.22 KB
/
JsonArray.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright Benoit Blanchon 2014
// MIT License
//
// Arduino JSON library
// https://github.com/bblanchon/ArduinoJson
#include "JsonArray.h"
#include "JsonBuffer.h"
#include "JsonObject.h"
using namespace ArduinoJson;
using namespace ArduinoJson::Internals;
JsonArray JsonArray::_invalid(NULL);
JsonVariant &JsonArray::at(int index) const {
node_type *node = _firstNode;
while (node && index--) node = node->next;
return node ? node->content : JsonVariant::invalid();
}
JsonVariant &JsonArray::add() {
node_type *node = createNode();
if (!node) return JsonVariant::invalid();
addNode(node);
return node->content;
}
JsonArray &JsonArray::createNestedArray() {
if (!_buffer) return JsonArray::invalid();
JsonArray &array = _buffer->createArray();
add(array);
return array;
}
JsonObject &JsonArray::createNestedObject() {
if (!_buffer) return JsonObject::invalid();
JsonObject &object = _buffer->createObject();
add(object);
return object;
}
void JsonArray::writeTo(JsonWriter &writer) const {
writer.beginArray();
const node_type *child = _firstNode;
while (child) {
child->content.writeTo(writer);
child = child->next;
if (!child) break;
writer.writeComma();
}
writer.endArray();
}