JSONParser.h 831 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include <cstdarg>
  3. #include "Types.h"
  4. #include "List.h"
  5. #include "HeapAllocator.h"
  6. #include "JSON.h"
  7. namespace crown
  8. {
  9. struct JSONNode
  10. {
  11. JSONType type;
  12. const char* key;
  13. const char* val;
  14. };
  15. class JSONParser
  16. {
  17. public:
  18. /// Constructor
  19. JSONParser(Allocator& allocator, const char* s);
  20. /// Get root element
  21. JSONParser& root();
  22. /// Get object @a key
  23. JSONParser& object(const char* key);
  24. /// Get array @a key and element @a index
  25. JSONParser& array(const char* key, uint32_t index);
  26. /// Get string
  27. const char* string(const char* key, List<char>& str);
  28. /// Get number
  29. double number(const char* key = NULL);
  30. /// Get boolean
  31. bool boolean(const char* key = NULL);
  32. void print_nodes();
  33. private:
  34. const char* m_buffer;
  35. List<JSONNode> m_nodes;
  36. };
  37. } // namespace crown