JsonObjectBase.cpp 564 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * malloc-free JSON parser for Arduino
  3. * Benoit Blanchon 2014
  4. * MIT License
  5. */
  6. #include "JsonObjectBase.h"
  7. int JsonObjectBase::getNestedTokenCount(jsmntok_t* token)
  8. {
  9. int count = 0;
  10. for (int i = 0; i < token->size; i++)
  11. {
  12. count += 1 + getNestedTokenCount(token + 1 + i);
  13. }
  14. return count;
  15. }
  16. char* JsonObjectBase::getTokenString(jsmntok_t* token)
  17. {
  18. if (token->type != JSMN_PRIMITIVE && token->type != JSMN_STRING)
  19. return 0;
  20. // add null terminator to the string
  21. json[token->end] = 0;
  22. return json + token->start;
  23. }