forked from bblanchon/ArduinoJson
Made it possible to use const JsonObject&
This commit is contained in:
@ -34,7 +34,9 @@ class JsonObject : public JsonPrintable<JsonObject>,
|
|||||||
int size() const;
|
int size() const;
|
||||||
|
|
||||||
JsonValue &at(key_type key);
|
JsonValue &at(key_type key);
|
||||||
JsonValue &operator[](key_type key) { return at(key); }
|
const JsonValue &at(key_type key) const;
|
||||||
|
JsonValue &operator[](key_type key);
|
||||||
|
const JsonValue &operator[](key_type key) const { return at(key); }
|
||||||
|
|
||||||
void remove(key_type key);
|
void remove(key_type key);
|
||||||
|
|
||||||
@ -68,7 +70,7 @@ class JsonObject : public JsonPrintable<JsonObject>,
|
|||||||
void addNode(Internals::JsonObjectNode *nodeToAdd);
|
void addNode(Internals::JsonObjectNode *nodeToAdd);
|
||||||
void removeNode(Internals::JsonObjectNode *nodeToRemove);
|
void removeNode(Internals::JsonObjectNode *nodeToRemove);
|
||||||
|
|
||||||
Internals::JsonObjectNode *getNodeAt(key_type key);
|
Internals::JsonObjectNode *getNodeAt(key_type key) const;
|
||||||
Internals::JsonObjectNode *getOrCreateNodeAt(key_type key);
|
Internals::JsonObjectNode *getOrCreateNodeAt(key_type key);
|
||||||
|
|
||||||
JsonBuffer *_buffer;
|
JsonBuffer *_buffer;
|
||||||
|
@ -27,6 +27,16 @@ int JsonObject::size() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JsonValue &JsonObject::at(const char *key) {
|
JsonValue &JsonObject::at(const char *key) {
|
||||||
|
JsonObjectNode *node = getNodeAt(key);
|
||||||
|
return node ? node->pair.value : JsonValue::invalid();
|
||||||
|
}
|
||||||
|
|
||||||
|
const JsonValue &JsonObject::at(const char *key) const {
|
||||||
|
JsonObjectNode *node = getNodeAt(key);
|
||||||
|
return node ? node->pair.value : JsonValue::invalid();
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonValue &JsonObject::operator[](const char *key) {
|
||||||
JsonObjectNode *node = getOrCreateNodeAt(key);
|
JsonObjectNode *node = getOrCreateNodeAt(key);
|
||||||
return node ? node->pair.value : JsonValue::invalid();
|
return node ? node->pair.value : JsonValue::invalid();
|
||||||
}
|
}
|
||||||
@ -47,7 +57,7 @@ JsonObject &JsonObject::createNestedObject(const char *key) {
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObjectNode *JsonObject::getNodeAt(const char *key) {
|
JsonObjectNode *JsonObject::getNodeAt(const char *key) const {
|
||||||
for (JsonObjectNode *node = _firstNode; node; node = node->next) {
|
for (JsonObjectNode *node = _firstNode; node; node = node->next) {
|
||||||
if (!strcmp(node->pair.key, key)) return node;
|
if (!strcmp(node->pair.key, key)) return node;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user