2014-07-03 13:58:08 +02:00
|
|
|
/*
|
|
|
|
* Arduino JSON library
|
|
|
|
* Benoit Blanchon 2014 - MIT License
|
|
|
|
*/
|
2014-01-11 15:05:35 +01:00
|
|
|
|
|
|
|
#include "JsonArray.h"
|
2014-07-18 16:46:01 +02:00
|
|
|
#include "JsonObject.h"
|
2014-01-11 15:05:35 +01:00
|
|
|
|
2014-07-03 14:00:51 +02:00
|
|
|
using namespace ArduinoJson::Parser;
|
2014-07-18 15:43:20 +02:00
|
|
|
using namespace ArduinoJson::Internal;
|
2014-07-03 14:00:51 +02:00
|
|
|
|
2014-07-18 16:46:01 +02:00
|
|
|
DEPRECATED JsonObject JsonArray::getHashTable(int index)
|
2014-01-12 20:30:24 +01:00
|
|
|
{
|
2014-07-18 16:46:01 +02:00
|
|
|
return (JsonObject) (*this)[index];
|
2014-01-12 20:30:24 +01:00
|
|
|
}
|
2014-07-18 15:43:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the token for the value at the specified index
|
|
|
|
*/
|
|
|
|
JsonValue JsonArray::operator[](int index)
|
|
|
|
{
|
|
|
|
// sanity check
|
|
|
|
if (index < 0 || !token.isArray() || index >= token.size())
|
|
|
|
return JsonValue::null();
|
|
|
|
|
|
|
|
// skip first token, it's the whole object
|
2014-07-18 15:54:49 +02:00
|
|
|
JsonToken runningToken = token.firstChild();
|
2014-07-18 15:43:20 +02:00
|
|
|
|
|
|
|
// skip all tokens before the specified index
|
|
|
|
for (int i = 0; i < index; i++)
|
|
|
|
{
|
|
|
|
// move forward: current + nested tokens
|
2014-07-18 15:54:49 +02:00
|
|
|
runningToken = runningToken.nextSibling();
|
2014-07-18 15:43:20 +02:00
|
|
|
}
|
|
|
|
|
2014-07-18 15:54:49 +02:00
|
|
|
return JsonValue(json, runningToken);
|
2014-07-18 15:43:20 +02:00
|
|
|
}
|