JsonArray.cpp 860 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Arduino JSON library
  3. * Benoit Blanchon 2014 - MIT License
  4. */
  5. #include "JsonArray.h"
  6. #include "JsonHashTable.h"
  7. using namespace ArduinoJson::Parser;
  8. /*
  9. * Returns the token for the value at the specified index
  10. */
  11. JsonValue JsonArray::operator[](int index)
  12. {
  13. // sanity check
  14. if (!success() || index < 0 || index >= tokens[0].size)
  15. return JsonValue();
  16. // skip first token, it's the whole object
  17. jsmntok_t* currentToken = tokens + 1;
  18. // skip all tokens before the specified index
  19. for (int i = 0; i < index; i++)
  20. {
  21. // move forward: current + nested tokens
  22. currentToken += 1 + getNestedTokenCount(currentToken);
  23. }
  24. return JsonValue(json, currentToken);
  25. }
  26. JsonHashTable JsonArray::getHashTable(int index) DEPRECATED
  27. {
  28. return (JsonHashTable) (*this)[index];
  29. }