JsonObject.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. // A JSON Object (ie hash-table/dictionary)
  14. class JsonObject : JsonValue
  15. {
  16. public:
  17. // Create an invalid JsonObject
  18. JsonObject()
  19. {
  20. }
  21. // Convert a JsonValue into a JsonObject
  22. JsonObject(JsonValue value)
  23. : JsonValue(value)
  24. {
  25. }
  26. // Tell if the object is valid
  27. bool success()
  28. {
  29. return isObject();
  30. }
  31. // Get the value associated with the specified key.
  32. JsonValue operator[](const char* key)
  33. {
  34. return JsonValue::operator[](key);
  35. }
  36. // Tell if the specified key exists in the object.
  37. bool containsKey(const char* key)
  38. {
  39. return operator[](key).success();
  40. }
  41. // Get an iterator pointing at the beginning of the object
  42. JsonObjectIterator begin()
  43. {
  44. return isObject() ? firstChild() : null();
  45. }
  46. // Get an iterator pointing at the end of the object
  47. JsonObjectIterator end()
  48. {
  49. return isObject() ? nextSibling() : null();
  50. }
  51. // Obsolete: Use operator[] instead
  52. DEPRECATED JsonArray getArray(const char* key);
  53. // Obsolete: Use operator[] instead
  54. DEPRECATED bool getBool(const char* key)
  55. {
  56. return operator[](key);
  57. }
  58. // Obsolete: Use operator[] instead
  59. DEPRECATED double getDouble(const char* key)
  60. {
  61. return operator[](key);
  62. }
  63. // Obsolete: Use operator[] instead
  64. DEPRECATED JsonObject getHashTable(const char* key)
  65. {
  66. return operator[](key);
  67. }
  68. // Obsolete: Use operator[] instead
  69. DEPRECATED long getLong(const char* key)
  70. {
  71. return operator[](key);
  72. }
  73. // Obsolete: Use operator[] instead
  74. DEPRECATED char* getString(const char* key)
  75. {
  76. return operator[](key);
  77. }
  78. };
  79. // Obsolete: Use JsonObject instead
  80. DEPRECATED typedef JsonObject JsonHashTable;
  81. }
  82. }