Files
ArduinoJson/JsonParser/JsonObject.h

102 lines
2.6 KiB
C
Raw Permalink Normal View History

2014-07-03 13:58:08 +02:00
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
2014-01-11 15:05:35 +01:00
2014-07-03 13:58:08 +02:00
#pragma once
2014-01-11 15:05:35 +01:00
#include "JsonValue.h"
2014-07-18 22:40:50 +02:00
#include "JsonObjectIterator.h"
2014-07-03 14:00:51 +02:00
namespace ArduinoJson
2014-01-11 15:05:35 +01:00
{
2014-07-03 14:00:51 +02:00
namespace Parser
{
class JsonArray;
2014-07-21 15:20:02 +02:00
// A JSON Object (ie hash-table/dictionary)
class JsonObject : JsonValue
2014-07-03 14:00:51 +02:00
{
public:
2014-07-21 15:20:02 +02:00
// Create an invalid JsonObject
2014-07-19 12:44:27 +02:00
JsonObject()
2014-07-18 16:46:01 +02:00
{
}
2014-07-21 15:20:02 +02:00
// Convert a JsonValue into a JsonObject
JsonObject(JsonValue value)
: JsonValue(value)
2014-07-18 15:43:20 +02:00
{
2014-07-19 12:44:27 +02:00
2014-07-18 15:43:20 +02:00
}
2014-01-11 15:05:35 +01:00
2014-07-21 15:20:02 +02:00
// Tell if the object is valid
bool success()
{
2014-07-19 12:44:27 +02:00
return isObject();
}
2014-07-21 15:20:02 +02:00
// Get the value associated with the specified key.
JsonValue operator[](const char* key)
{
return JsonValue::operator[](key);
}
2014-07-21 15:20:02 +02:00
// Tell if the specified key exists in the object.
bool containsKey(const char* key)
{
return operator[](key).success();
}
2014-07-18 22:40:50 +02:00
2014-07-21 15:20:02 +02:00
// Get an iterator pointing at the beginning of the object
2014-07-18 22:40:50 +02:00
JsonObjectIterator begin()
{
return isObject() ? firstChild() : null();
2014-07-18 22:40:50 +02:00
}
2014-07-21 15:20:02 +02:00
// Get an iterator pointing at the end of the object
2014-07-18 22:40:50 +02:00
JsonObjectIterator end()
{
return isObject() ? nextSibling() : null();
2014-07-18 22:40:50 +02:00
}
2014-07-21 15:20:02 +02:00
// Obsolete: Use operator[] instead
2014-07-16 13:53:56 +02:00
DEPRECATED JsonArray getArray(const char* key);
2014-07-21 15:20:02 +02:00
// Obsolete: Use operator[] instead
2014-07-16 13:53:56 +02:00
DEPRECATED bool getBool(const char* key)
{
return operator[](key);
}
2014-07-21 15:20:02 +02:00
// Obsolete: Use operator[] instead
2014-07-16 13:53:56 +02:00
DEPRECATED double getDouble(const char* key)
{
return operator[](key);
}
2014-07-21 15:20:02 +02:00
// Obsolete: Use operator[] instead
2014-07-18 16:46:01 +02:00
DEPRECATED JsonObject getHashTable(const char* key)
{
return operator[](key);
}
2014-07-21 15:20:02 +02:00
// Obsolete: Use operator[] instead
2014-07-16 13:53:56 +02:00
DEPRECATED long getLong(const char* key)
{
return operator[](key);
}
2014-01-13 19:46:53 +01:00
2014-07-21 15:20:02 +02:00
// Obsolete: Use operator[] instead
2014-07-16 13:53:56 +02:00
DEPRECATED char* getString(const char* key)
{
return operator[](key);
2014-07-18 15:43:20 +02:00
}
2014-07-03 14:00:51 +02:00
};
2014-07-18 16:46:01 +02:00
2014-07-21 15:20:02 +02:00
// Obsolete: Use JsonObject instead
DEPRECATED typedef JsonObject JsonHashTable;
2014-07-03 14:00:51 +02:00
}
}