2014-10-19 15:46:36 +02:00
|
|
|
#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-16 16:25:42 +02:00
|
|
|
JsonValue JsonArray::operator[](int index) const
|
|
|
|
{
|
|
|
|
for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it)
|
|
|
|
{
|
|
|
|
if (!index) return JsonValue(*it);
|
|
|
|
index--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return JsonValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void JsonArray::add(bool value)
|
|
|
|
{
|
|
|
|
JsonNode* node = createNode();
|
|
|
|
if (!node) return;
|
|
|
|
|
|
|
|
node->setAsBoolean(value);
|
|
|
|
addChild(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JsonArray::add(char const* value)
|
|
|
|
{
|
|
|
|
JsonNode* node = createNode();
|
|
|
|
if (!node) return;
|
|
|
|
|
|
|
|
node->setAsString(value);
|
|
|
|
addChild(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JsonArray::add(double value, int decimals)
|
|
|
|
{
|
|
|
|
JsonNode* node = createNode();
|
|
|
|
if (!node) return;
|
|
|
|
|
|
|
|
node->setAsDouble(value, decimals);
|
|
|
|
addChild(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JsonArray::add(long value)
|
|
|
|
{
|
|
|
|
JsonNode* node = createNode();
|
|
|
|
if (!node) return;
|
|
|
|
|
|
|
|
node->setAsLong(value);
|
|
|
|
addChild(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: we should have the same issue as in JsonValue
|
|
|
|
void JsonArray::add(JsonContainer nestedContainer)
|
|
|
|
{
|
|
|
|
JsonNode* node = createNode();
|
|
|
|
if (!node) return;
|
|
|
|
|
|
|
|
node->duplicate(nestedContainer._node);
|
|
|
|
addChild(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonArray 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);
|
2014-10-22 17:59:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
JsonArrayIterator JsonArray::begin()
|
|
|
|
{
|
|
|
|
if (!_node)
|
|
|
|
return end();
|
|
|
|
|
|
|
|
return JsonArrayIterator(_node->getContainerChild());
|
2014-10-05 14:55:14 +02:00
|
|
|
}
|