JsonObjectBase.h 788 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * malloc-free JSON parser for Arduino
  3. * Benoit Blanchon 2014
  4. * MIT License
  5. */
  6. #ifndef __JSONOBJECTBASE_H
  7. #define __JSONOBJECTBASE_H
  8. #include "jsmn.h"
  9. class JsonObjectBase
  10. {
  11. public:
  12. JsonObjectBase()
  13. {
  14. makeInvalid();
  15. }
  16. bool success()
  17. {
  18. return json != 0 && tokens != 0;
  19. }
  20. protected:
  21. JsonObjectBase(char* json, jsmntok_t* tokens)
  22. {
  23. this->json = json;
  24. this->tokens = tokens;
  25. }
  26. void makeInvalid()
  27. {
  28. json = 0;
  29. tokens = 0;
  30. }
  31. static int getNestedTokenCount(jsmntok_t* token);
  32. bool getBoolFromToken(jsmntok_t* token);
  33. double getDoubleFromToken(jsmntok_t* token);
  34. long getLongFromToken(jsmntok_t* token);
  35. char* getStringFromToken(jsmntok_t* token);
  36. char* json;
  37. jsmntok_t* tokens;
  38. };
  39. #endif