mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 12:02:14 +02:00
Fixed inner object bug
This commit is contained in:
@ -5,6 +5,7 @@ class JsonBuffer;
|
||||
enum JsonNodeType
|
||||
{
|
||||
JSON_UNDEFINED,
|
||||
JSON_PROXY,
|
||||
JSON_NULL,
|
||||
JSON_ARRAY,
|
||||
JSON_OBJECT,
|
||||
@ -42,5 +43,10 @@ struct JsonNode
|
||||
JsonBuffer* buffer;
|
||||
} asObject;
|
||||
|
||||
struct
|
||||
{
|
||||
JsonNode* target;
|
||||
} asProxy;
|
||||
|
||||
} content;
|
||||
};
|
@ -51,6 +51,11 @@ JsonValue JsonObject::operator[](char const* key)
|
||||
return JsonValue(node);
|
||||
}
|
||||
|
||||
bool JsonObject::operator==(JsonObject const& other) const
|
||||
{
|
||||
return _node == other._node;
|
||||
}
|
||||
|
||||
JsonNode* JsonObject::getOrCreateNodeAt(char const* key)
|
||||
{
|
||||
if (!_node || _node->type != JSON_OBJECT) return 0;
|
||||
|
@ -22,10 +22,7 @@ public:
|
||||
|
||||
JsonValue operator[](const char* key);
|
||||
|
||||
bool operator== (const JsonObject& other) const
|
||||
{
|
||||
return _node == other._node;
|
||||
}
|
||||
bool operator==(const JsonObject& other) const;
|
||||
|
||||
private:
|
||||
JsonNode* _node;
|
||||
|
@ -36,40 +36,62 @@ void JsonValue::operator=(int value)
|
||||
|
||||
void JsonValue::operator=(const JsonObject& object)
|
||||
{
|
||||
if (!_node) return;
|
||||
if (_node)
|
||||
{
|
||||
_node->type = JSON_PROXY;
|
||||
_node->content.asProxy.target = object._node;
|
||||
}
|
||||
|
||||
_node = object._node;
|
||||
}
|
||||
|
||||
JsonValue::operator bool() const
|
||||
{
|
||||
if (!_node || _node->type != JSON_BOOLEAN) return 0;
|
||||
const JsonNode* node = getActualNode();
|
||||
|
||||
return _node->content.asBoolean;
|
||||
if (!node || node->type != JSON_BOOLEAN) return 0;
|
||||
|
||||
return node->content.asBoolean;
|
||||
}
|
||||
|
||||
JsonValue::operator char const*() const
|
||||
{
|
||||
if (!_node || _node->type != JSON_STRING) return 0;
|
||||
const JsonNode* node = getActualNode();
|
||||
|
||||
return _node->content.asString;
|
||||
if (!node || node->type != JSON_STRING) return 0;
|
||||
|
||||
return node->content.asString;
|
||||
}
|
||||
|
||||
JsonValue::operator double() const
|
||||
{
|
||||
if (!_node || _node->type < JSON_DOUBLE_0_DECIMALS) return 0;
|
||||
const JsonNode* node = getActualNode();
|
||||
|
||||
return _node->content.asDouble;
|
||||
if (!node || node->type < JSON_DOUBLE_0_DECIMALS) return 0;
|
||||
|
||||
return node->content.asDouble;
|
||||
}
|
||||
|
||||
JsonValue::operator int() const
|
||||
{
|
||||
if (!_node || _node->type != JSON_INTEGER) return 0;
|
||||
const JsonNode* node = getActualNode();
|
||||
|
||||
return _node->content.asInteger;
|
||||
if (!node || node->type != JSON_INTEGER) return 0;
|
||||
|
||||
return node->content.asInteger;
|
||||
}
|
||||
|
||||
JsonValue::operator JsonObject() const
|
||||
{
|
||||
return JsonObject(_node);
|
||||
return JsonObject(getActualNode());
|
||||
}
|
||||
|
||||
JsonNode* JsonValue::getActualNode() const
|
||||
{
|
||||
JsonNode* target = _node;
|
||||
|
||||
while (target && target->type == JSON_PROXY)
|
||||
target = target->content.asProxy.target;
|
||||
|
||||
return target;
|
||||
}
|
@ -30,5 +30,7 @@ public:
|
||||
|
||||
private:
|
||||
JsonNode* _node;
|
||||
|
||||
JsonNode* getActualNode() const;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user