JsonArray.cpp 901 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. using namespace ArduinoJson::Internal;
  9. DEPRECATED JsonHashTable JsonArray::getHashTable(int index)
  10. {
  11. return (JsonHashTable) (*this)[index];
  12. }
  13. /*
  14. * Returns the token for the value at the specified index
  15. */
  16. JsonValue JsonArray::operator[](int index)
  17. {
  18. // sanity check
  19. if (index < 0 || !token.isArray() || index >= token.size())
  20. return JsonValue::null();
  21. // skip first token, it's the whole object
  22. JsonToken runningToken = token.firstChild();
  23. // skip all tokens before the specified index
  24. for (int i = 0; i < index; i++)
  25. {
  26. // move forward: current + nested tokens
  27. runningToken = runningToken.nextSibling();
  28. }
  29. return JsonValue(json, runningToken);
  30. }