JsonArray.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Arduino JSON library
  3. * Benoit Blanchon 2014 - MIT License
  4. */
  5. #pragma once
  6. #include "JsonValue.h"
  7. #include "JsonArrayIterator.h"
  8. namespace ArduinoJson
  9. {
  10. namespace Parser
  11. {
  12. class JsonObject;
  13. // A JSON array
  14. class JsonArray : JsonValue
  15. {
  16. public:
  17. // Create an invalid array
  18. JsonArray()
  19. {
  20. }
  21. // Convert a JsonValue into a JsonArray
  22. JsonArray(JsonValue value)
  23. : JsonValue(value)
  24. {
  25. }
  26. // Tell if the array is valid
  27. bool success()
  28. {
  29. return isArray();
  30. }
  31. // Get the JsonValue at specified index
  32. JsonValue operator[](int index)
  33. {
  34. return JsonValue::operator[](index);
  35. }
  36. // Get the size of the array
  37. int size()
  38. {
  39. return isArray() ? childrenCount() : 0;
  40. }
  41. // Get an iterator pointing to the beginning of the array
  42. JsonArrayIterator begin()
  43. {
  44. return isArray() ? firstChild() : null();
  45. }
  46. // Gets an iterator pointing to the end of the array
  47. JsonArrayIterator end()
  48. {
  49. return isArray() ? nextSibling() : null();
  50. }
  51. // Obsolete: Use size() instead
  52. DEPRECATED int getLength()
  53. {
  54. return size();
  55. }
  56. // Obsolete: Use operator[] instead
  57. DEPRECATED JsonArray getArray(int index)
  58. {
  59. return operator[](index);
  60. }
  61. // Obsolete: Use operator[] instead
  62. DEPRECATED bool getBool(int index)
  63. {
  64. return operator[](index);
  65. }
  66. // Obsolete: Use operator[] instead
  67. DEPRECATED double getDouble(int index)
  68. {
  69. return operator[](index);
  70. }
  71. // Obsolete: Use operator[] instead
  72. DEPRECATED JsonObject getHashTable(int index);
  73. // Obsolete: Use operator[] instead
  74. DEPRECATED long getLong(int index)
  75. {
  76. return operator[](index);
  77. }
  78. // Obsolete: Use operator[] instead
  79. DEPRECATED char* getString(int index)
  80. {
  81. return operator[](index);
  82. }
  83. };
  84. }
  85. }