JsonArray.cpp 796 B

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