JsonValue.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Arduino JSON library
  3. * Benoit Blanchon 2014 - MIT License
  4. */
  5. #pragma once
  6. #include "JsonToken.h"
  7. #ifndef ARDUINO_JSON_NO_DEPRECATION_WARNING
  8. #ifdef __GNUC__
  9. #define DEPRECATED __attribute__((deprecated))
  10. #elif defined(_MSC_VER)
  11. #define DEPRECATED __declspec(deprecated)
  12. #endif
  13. #else
  14. #define DEPRECATED
  15. #endif
  16. namespace ArduinoJson
  17. {
  18. namespace Parser
  19. {
  20. // A JSON value
  21. // Can be converted to string, double, bool, array or object.
  22. class JsonValue : protected JsonToken
  23. {
  24. public:
  25. // Create a invalid value
  26. JsonValue()
  27. {
  28. }
  29. // Convert a JsonToken to a JsonValue
  30. JsonValue(JsonToken token)
  31. : JsonToken(token)
  32. {
  33. }
  34. // Tell is the JsonValue is valid
  35. bool success()
  36. {
  37. return isValid();
  38. }
  39. // Convert the JsonValue to a bool.
  40. // Returns false if the JsonValue is not a primitve.
  41. operator bool();
  42. // Convert the JsonValue to a floating point value.
  43. // Returns false if the JsonValue is not a number.
  44. operator double();
  45. // Convert the JsonValue to a long integer.
  46. // Returns 0 if the JsonValue is not a number.
  47. operator long();
  48. // Convert the JsonValue to a string.
  49. // Returns 0 if the JsonValue is not a string.
  50. operator char*();
  51. // Get the nested value at the specified index.
  52. // Returns an invalid JsonValue if the current value is not an array.
  53. JsonValue operator[](int index);
  54. // Get the nested value matching the specified index.
  55. // Returns an invalid JsonValue if the current value is not an object.
  56. JsonValue operator[](const char* key);
  57. };
  58. }
  59. }