2014-07-03 13:58:08 +02:00
|
|
|
/*
|
|
|
|
* Arduino JSON library
|
|
|
|
* Benoit Blanchon 2014 - MIT License
|
|
|
|
*/
|
2014-09-27 21:24:29 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "JsonValue.h"
|
|
|
|
#include "JsonArrayIterator.h"
|
|
|
|
|
|
|
|
namespace ArduinoJson
|
|
|
|
{
|
|
|
|
namespace Parser
|
|
|
|
{
|
|
|
|
class JsonObject;
|
2014-07-21 14:14:31 +02:00
|
|
|
|
2014-07-21 15:20:02 +02:00
|
|
|
// A JSON array
|
2014-09-27 21:24:29 +02:00
|
|
|
class JsonArray : JsonValue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-07-21 15:20:02 +02:00
|
|
|
// Create an invalid array
|
2014-09-27 21:24:29 +02:00
|
|
|
JsonArray()
|
|
|
|
{
|
|
|
|
}
|
2014-07-21 14:14:31 +02:00
|
|
|
|
2014-07-21 15:20:02 +02:00
|
|
|
// Convert a JsonValue into a JsonArray
|
2014-09-27 21:24:29 +02:00
|
|
|
JsonArray(JsonValue value)
|
|
|
|
: JsonValue(value)
|
|
|
|
{
|
|
|
|
}
|
2014-07-21 14:14:31 +02:00
|
|
|
|
2014-07-21 15:20:02 +02:00
|
|
|
// Tell if the array is valid
|
2014-09-27 21:24:29 +02:00
|
|
|
bool success()
|
|
|
|
{
|
|
|
|
return isArray();
|
|
|
|
}
|
2014-07-21 14:14:31 +02:00
|
|
|
|
2014-07-21 15:20:02 +02:00
|
|
|
// Get the JsonValue at specified index
|
2014-09-27 21:24:29 +02:00
|
|
|
JsonValue operator[](int index)
|
|
|
|
{
|
|
|
|
return JsonValue::operator[](index);
|
|
|
|
}
|
2014-07-21 14:14:31 +02:00
|
|
|
|
2014-07-21 15:20:02 +02:00
|
|
|
// Get the size of the array
|
2014-09-27 21:24:29 +02:00
|
|
|
int size()
|
|
|
|
{
|
|
|
|
return isArray() ? childrenCount() : 0;
|
|
|
|
}
|
2014-07-21 14:14:31 +02:00
|
|
|
|
2014-07-21 15:20:02 +02:00
|
|
|
// Get an iterator pointing to the beginning of the array
|
2014-09-27 21:24:29 +02:00
|
|
|
JsonArrayIterator begin()
|
|
|
|
{
|
|
|
|
return isArray() ? firstChild() : null();
|
|
|
|
}
|
2014-07-21 14:14:31 +02:00
|
|
|
|
2014-07-21 15:20:02 +02:00
|
|
|
// Gets an iterator pointing to the end of the array
|
2014-09-27 21:24:29 +02:00
|
|
|
JsonArrayIterator end()
|
|
|
|
{
|
|
|
|
return isArray() ? nextSibling() : null();
|
|
|
|
}
|
2014-07-21 14:14:31 +02:00
|
|
|
|
2014-07-21 15:20:02 +02:00
|
|
|
// Obsolete: Use size() instead
|
2014-09-27 21:24:29 +02:00
|
|
|
DEPRECATED int getLength()
|
|
|
|
{
|
|
|
|
return size();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obsolete: Use operator[] instead
|
|
|
|
DEPRECATED JsonArray getArray(int index)
|
|
|
|
{
|
|
|
|
return operator[](index);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obsolete: Use operator[] instead
|
|
|
|
DEPRECATED bool getBool(int index)
|
|
|
|
{
|
|
|
|
return operator[](index);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obsolete: Use operator[] instead
|
|
|
|
DEPRECATED double getDouble(int index)
|
|
|
|
{
|
|
|
|
return operator[](index);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obsolete: Use operator[] instead
|
|
|
|
DEPRECATED JsonObject getHashTable(int index);
|
|
|
|
|
|
|
|
// Obsolete: Use operator[] instead
|
|
|
|
DEPRECATED long getLong(int index)
|
|
|
|
{
|
|
|
|
return operator[](index);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obsolete: Use operator[] instead
|
|
|
|
DEPRECATED char* getString(int index)
|
|
|
|
{
|
|
|
|
return operator[](index);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|