Fixed JsonVariant::success() which didn't propagate JsonArray::success() nor JsonObject::success() (issue #342).

This commit is contained in:
Benoit Blanchon
2016-08-29 20:54:39 +02:00
parent e401498e4a
commit ffb9b6d1ba
6 changed files with 87 additions and 24 deletions

View File

@ -8,11 +8,29 @@
#pragma once
#include "JsonArray.hpp"
#include "JsonObject.hpp"
#include "JsonArraySubscript.hpp"
#include "JsonObject.hpp"
namespace ArduinoJson {
inline JsonVariant::JsonVariant(JsonArray &array) {
if (array.success()) {
_type = Internals::JSON_ARRAY;
_content.asArray = &array;
} else {
_type = Internals::JSON_UNDEFINED;
}
}
inline JsonVariant::JsonVariant(JsonObject &object) {
if (object.success()) {
_type = Internals::JSON_OBJECT;
_content.asObject = &object;
} else {
_type = Internals::JSON_UNDEFINED;
}
}
template <>
inline bool JsonArray::setNodeValue(node_type *node, String &value) {
const char *copy = _buffer->strdup(value);

View File

@ -107,16 +107,10 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
}
// Create a JsonVariant containing a reference to an array.
JsonVariant(JsonArray &array) {
_type = Internals::JSON_ARRAY;
_content.asArray = &array;
}
JsonVariant(JsonArray &array);
// Create a JsonVariant containing a reference to an object.
JsonVariant(JsonObject &object) {
_type = Internals::JSON_OBJECT;
_content.asObject = &object;
}
JsonVariant(JsonObject &object);
// Get the variant as the specified type.
//