2014-07-16 13:26:11 +02:00
|
|
|
/*
|
|
|
|
* Arduino JSON library
|
|
|
|
* Benoit Blanchon 2014 - MIT License
|
2014-07-22 20:14:25 +02:00
|
|
|
*/
|
2014-07-17 13:27:40 +02:00
|
|
|
|
2014-07-22 20:14:25 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "JsonToken.h"
|
|
|
|
|
|
|
|
#ifndef ARDUINO_JSON_NO_DEPRECATED_WARNING
|
2014-07-17 13:12:12 +02:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define DEPRECATED __attribute__((deprecated))
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
#define DEPRECATED __declspec(deprecated)
|
2014-07-22 20:14:25 +02:00
|
|
|
#endif
|
2014-07-17 13:27:40 +02:00
|
|
|
#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-17 13:12:12 +02:00
|
|
|
|
2014-07-22 20:14:25 +02:00
|
|
|
// Create a invalid value
|
2014-07-19 14:41:29 +02:00
|
|
|
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-17 13:12:12 +02:00
|
|
|
}
|
|
|
|
|
2014-07-22 20:14:25 +02:00
|
|
|
// Tell is the JsonValue is valid
|
2014-07-17 13:12:12 +02:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
}
|
2014-07-16 13:26:11 +02:00
|
|
|
}
|