JsonObject.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Arduino JSON library
  3. * Benoit Blanchon 2014 - MIT License
  4. */
  5. #pragma once
  6. #include "JsonValue.h"
  7. #include "JsonObjectIterator.h"
  8. namespace ArduinoJson
  9. {
  10. namespace Parser
  11. {
  12. class JsonArray;
  13. class JsonObject
  14. {
  15. public:
  16. JsonObject(char* json, Internal::JsonToken token)
  17. : json(json), token(token)
  18. {
  19. }
  20. JsonObject()
  21. : token(Internal::JsonToken::null())
  22. {
  23. }
  24. bool success()
  25. {
  26. return token.isObject();
  27. }
  28. JsonValue operator[](const char* key)
  29. {
  30. return getValue(key);
  31. }
  32. bool containsKey(const char* key)
  33. {
  34. return getValue(key).success();
  35. }
  36. JsonObjectIterator begin()
  37. {
  38. return JsonObjectIterator(json, token.firstChild());
  39. }
  40. JsonObjectIterator end()
  41. {
  42. return JsonObjectIterator(json, token.nextSibling());
  43. }
  44. DEPRECATED JsonArray getArray(const char* key);
  45. DEPRECATED bool getBool(const char* key)
  46. {
  47. return getValue(key);
  48. }
  49. DEPRECATED double getDouble(const char* key)
  50. {
  51. return getValue(key);
  52. }
  53. DEPRECATED JsonObject getHashTable(const char* key)
  54. {
  55. return getValue(key);
  56. }
  57. DEPRECATED long getLong(const char* key)
  58. {
  59. return getValue(key);
  60. }
  61. DEPRECATED char* getString(const char* key)
  62. {
  63. return getValue(key);
  64. }
  65. static JsonObject null()
  66. {
  67. return JsonObject();
  68. }
  69. private:
  70. char* json;
  71. Internal::JsonToken token;
  72. JsonValue getValue(const char* key);
  73. };
  74. typedef JsonObject JsonHashTable;
  75. }
  76. }