diff --git a/samples/Jzon.cpp b/samples/Jzon.cpp index 10d7b389ab..bc819dbeb7 100644 --- a/samples/Jzon.cpp +++ b/samples/Jzon.cpp @@ -92,37 +92,37 @@ namespace Jzon Object &Node::AsObject() { if (IsObject()) - return static_cast(*this); + return dynamic_cast(*this); throw TypeException(); } const Object &Node::AsObject() const { if (IsObject()) - return static_cast(*this); + return dynamic_cast(*this); throw TypeException(); } Array &Node::AsArray() { if (IsArray()) - return static_cast(*this); + return dynamic_cast(*this); throw TypeException(); } const Array &Node::AsArray() const { if (IsArray()) - return static_cast(*this); + return dynamic_cast(*this); throw TypeException(); } Value &Node::AsValue() { if (IsValue()) - return static_cast(*this); + return dynamic_cast(*this); throw TypeException(); } const Value &Node::AsValue() const { if (IsValue()) - return static_cast(*this); + return dynamic_cast(*this); throw TypeException(); } @@ -1072,15 +1072,14 @@ namespace Jzon if (data.front().first == Value::VT_STRING) { - static_cast(node)->Set(data.front().second); // This method calls UnescapeString() - } - else - { - static_cast(node)->Set(data.front().first, data.front().second); - } - data.pop(); - - if (!nodeStack.empty()) + dynamic_cast(node)->Set( + data.front().second); // This method calls UnescapeString() + } else { + dynamic_cast(node)->Set(data.front().first, data.front().second); + } + data.pop(); + + if (!nodeStack.empty()) { if (nodeStack.top().second->IsObject()) nodeStack.top().second->AsObject().Add(name, *node); diff --git a/samples/exiv2json.cpp b/samples/exiv2json.cpp index 4bf8584c6c..284a0af236 100644 --- a/samples/exiv2json.cpp +++ b/samples/exiv2json.cpp @@ -98,7 +98,7 @@ Jzon::Node& addToTree(Jzon::Node& r1, const Token& token) std::string key = token.n ; size_t index = token.i-1; // array Eg: "History[1]" indexed from 1. Jzon expects 0 based index. - Jzon::Node& empty = token.a ? (Jzon::Node&) array : (Jzon::Node&) object ; + auto& empty = token.a ? static_cast(array) : static_cast(object); if ( r1.IsObject() ) { Jzon::Object& o1 = r1.AsObject(); @@ -246,7 +246,7 @@ void push(Jzon::Node& node,const std::string& key,T i) void fileSystemPush(const char* path,Jzon::Node& nfs) { - auto& fs = (Jzon::Object&)nfs; + auto& fs = dynamic_cast(nfs); fs.Add("path",path); char resolved_path[2000]; // PATH_MAX]; fs.Add("realpath",realpath(path,resolved_path));