Files
ArduinoJson/JsonParser/JsonValue.h

72 lines
2.0 KiB
C
Raw Normal View History

/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
2014-07-22 20:14:25 +02:00
*/
2014-07-22 20:14:25 +02:00
#pragma once
#include "JsonToken.h"
#ifndef ARDUINO_JSON_NO_DEPRECATED_WARNING
#ifdef __GNUC__
#define DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED __declspec(deprecated)
2014-07-22 20:14:25 +02:00
#endif
#else
#define DEPRECATED
2014-07-22 20:14:25 +02:00
#endif
namespace ArduinoJson
{
namespace Parser
{
// A JSON value
// Can be converted to string, double, bool, array or object.
class JsonValue : protected JsonToken
{
2014-07-18 15:43:20 +02:00
public:
2014-07-22 20:14:25 +02:00
// Create a invalid value
JsonValue()
{
}
2014-07-22 20:14:25 +02:00
// Convert a JsonToken to a JsonValue
2014-07-19 12:44:27 +02:00
JsonValue(JsonToken token)
: JsonToken(token)
{
}
2014-07-22 20:14:25 +02:00
// Tell is the JsonValue is valid
bool success()
{
2014-07-19 12:44:27 +02:00
return isValid();
2014-07-18 15:43:20 +02:00
}
2014-07-22 20:14:25 +02:00
// Convert the JsonValue to a bool.
// Returns false if the JsonValue is not a boolean.
operator bool();
// Convert the JsonValue to a floating point value.
// Returns false if the JsonValue is not a number.
operator double();
// Convert the JsonValue to a long integer.
// Returns 0 if the JsonValue is not a number.
operator long();
// Convert the JsonValue to a string.
// Returns 0 if the JsonValue is not a string.
operator char*();
// Get the nested value at the specified index.
// Returns an invalid JsonValue if the current value is not an array.
JsonValue operator[](int index);
// Get the nested value matching the specified index.
// Returns an invalid JsonValue if the current value is not an object.
JsonValue operator[](const char* key);
};
}
}