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-01-11 15:11:23 +01:00
|
|
|
#include "JsonHashTable.h"
|
2014-01-11 15:05:35 +01:00
|
|
|
|
2014-07-03 14:00:51 +02:00
|
|
|
using namespace ArduinoJson::Parser;
|
|
|
|
|
2014-01-11 16:41:18 +01:00
|
|
|
/*
|
|
|
|
* Returns the token for the value at the specified index
|
|
|
|
*/
|
2014-07-16 13:26:11 +02:00
|
|
|
JsonValue JsonArray::operator[](int index)
|
2014-01-11 15:05:35 +01:00
|
|
|
{
|
2014-07-16 13:41:00 +02:00
|
|
|
// sanity check
|
|
|
|
if (!success() || index < 0 || index >= tokens[0].size)
|
2014-07-16 13:26:11 +02:00
|
|
|
return JsonValue();
|
2014-01-11 15:05:35 +01:00
|
|
|
|
2014-07-16 13:41:00 +02:00
|
|
|
// skip first token, it's the whole object
|
|
|
|
jsmntok_t* currentToken = tokens + 1;
|
2014-01-11 15:05:35 +01:00
|
|
|
|
2014-07-16 13:41:00 +02:00
|
|
|
// skip all tokens before the specified index
|
|
|
|
for (int i = 0; i < index; i++)
|
|
|
|
{
|
|
|
|
// move forward: current + nested tokens
|
|
|
|
currentToken += 1 + getNestedTokenCount(currentToken);
|
|
|
|
}
|
2014-01-11 15:05:35 +01:00
|
|
|
|
2014-07-16 13:41:00 +02:00
|
|
|
return JsonValue(json, currentToken);
|
2014-01-11 15:05:35 +01:00
|
|
|
}
|
|
|
|
|
2014-01-11 15:11:23 +01:00
|
|
|
|
2014-07-16 13:53:56 +02:00
|
|
|
DEPRECATED JsonHashTable JsonArray::getHashTable(int index)
|
2014-01-12 20:30:24 +01:00
|
|
|
{
|
2014-07-16 13:26:11 +02:00
|
|
|
return (JsonHashTable) (*this)[index];
|
2014-01-12 20:30:24 +01:00
|
|
|
}
|