JsonArray.cpp 623 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * malloc-free JSON parser for Arduino
  3. * Benoit Blanchon 2014
  4. * MIT License
  5. */
  6. #include "JsonArray.h"
  7. jsmntok_t* JsonArray::getToken(int index)
  8. {
  9. if (json == 0 || tokens == 0 || index < 0 || index >= tokens[0].size)
  10. return 0;
  11. // skip first token, it's the whole object
  12. int currentToken = 1;
  13. for (int i = 0; i < index; i++)
  14. {
  15. // move forward: current + nested tokens
  16. currentToken += 1 + getNestedTokenCounts(currentToken);
  17. }
  18. return &tokens[currentToken];
  19. }
  20. JsonArray JsonArray::getArray(int index)
  21. {
  22. jsmntok_t* token = getToken(index);
  23. return JsonArray(json, token);
  24. }