mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
GH #144: Poco::Dynamic emits invalid JSON
GH #144: Poco::Dynamic emits invalid JSON
This commit is contained in:
@@ -120,6 +120,13 @@ public:
|
||||
return _data.second;
|
||||
}
|
||||
|
||||
std::string toString()
|
||||
{
|
||||
std::string str;
|
||||
Var(*this).convert<std::string>(str);
|
||||
return str;
|
||||
}
|
||||
|
||||
private:
|
||||
Data _data;
|
||||
};
|
||||
@@ -208,9 +215,9 @@ public:
|
||||
// JSON format definition: { string ':' value } string:value pair n-times, sep. by ','
|
||||
val.append("{ ");
|
||||
Var key(_val.first());
|
||||
appendJSONString(val, key);
|
||||
appendJSONKey(val, key);
|
||||
val.append(" : ");
|
||||
appendJSONString(val, _val.second());
|
||||
appendJSONValue(val, _val.second());
|
||||
val.append(" }");
|
||||
}
|
||||
|
||||
@@ -357,9 +364,9 @@ public:
|
||||
// JSON format definition: { string ':' value } string:value pair n-times, sep. by ','
|
||||
val.append("{ ");
|
||||
Var key(_val.first());
|
||||
appendJSONString(val, key);
|
||||
appendJSONKey(val, key);
|
||||
val.append(" : ");
|
||||
appendJSONString(val, _val.second());
|
||||
appendJSONValue(val, _val.second());
|
||||
val.append(" }");
|
||||
}
|
||||
|
||||
|
||||
@@ -204,6 +204,13 @@ public:
|
||||
return keys;
|
||||
}
|
||||
|
||||
std::string toString()
|
||||
{
|
||||
std::string str;
|
||||
Var(*this).convert<std::string>(str);
|
||||
return str;
|
||||
}
|
||||
|
||||
private:
|
||||
Data _data;
|
||||
};
|
||||
@@ -294,20 +301,20 @@ public:
|
||||
if (!_val.empty())
|
||||
{
|
||||
Var key(it->first);
|
||||
appendJSONString(val, key);
|
||||
appendJSONKey(val, key);
|
||||
val.append(" : ");
|
||||
appendJSONString(val, it->second);
|
||||
appendJSONValue(val, it->second);
|
||||
++it;
|
||||
}
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
val.append(", ");
|
||||
Var key(it->first);
|
||||
appendJSONString(val, key);
|
||||
appendJSONKey(val, key);
|
||||
val.append(" : ");
|
||||
appendJSONString(val, it->second);
|
||||
appendJSONValue(val, it->second);
|
||||
}
|
||||
val.append(" }");
|
||||
val.append(" }");
|
||||
}
|
||||
|
||||
void convert(Poco::DateTime&) const
|
||||
@@ -465,18 +472,18 @@ public:
|
||||
if (!_val.empty())
|
||||
{
|
||||
Var key(it->first);
|
||||
appendJSONString(val, key);
|
||||
appendJSONKey(val, key);
|
||||
val.append(" : ");
|
||||
appendJSONString(val, it->second);
|
||||
appendJSONValue(val, it->second);
|
||||
++it;
|
||||
}
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
val.append(", ");
|
||||
Var key(it->first);
|
||||
appendJSONString(val, key);
|
||||
appendJSONKey(val, key);
|
||||
val.append(" : ");
|
||||
appendJSONString(val, it->second);
|
||||
appendJSONValue(val, it->second);
|
||||
}
|
||||
val.append(" }");
|
||||
}
|
||||
|
||||
@@ -70,8 +70,20 @@ bool Foundation_API isJSONString(const Var& any);
|
||||
/// Returns true for values that should be JSON-formatted as string.
|
||||
|
||||
|
||||
void Foundation_API appendJSONKey(std::string& val, const Var& any);
|
||||
/// Converts the any to a JSON key (i.e. wraps it into double quotes
|
||||
/// regardless of the underlying type) and appends it to val.
|
||||
|
||||
|
||||
void Foundation_API appendJSONString(std::string& val, const Var& any);
|
||||
/// Converts the any to a JSON value and adds it to val
|
||||
/// Converts the any to a JSON string (i.e. wraps it into double quotes)
|
||||
/// regardless of the underlying type) and appends it to val.
|
||||
|
||||
|
||||
void Foundation_API appendJSONValue(std::string& val, const Var& any);
|
||||
/// Converts the any to a JSON value (if underlying type qualifies
|
||||
/// as string - see isJSONString() - , it is wrapped into double quotes)
|
||||
/// and appends it to val
|
||||
|
||||
|
||||
class Foundation_API VarHolder
|
||||
@@ -2694,14 +2706,14 @@ public:
|
||||
typename std::vector<T>::const_iterator itEnd = _val.end();
|
||||
if (!_val.empty())
|
||||
{
|
||||
appendJSONString(val, *it);
|
||||
appendJSONValue(val, *it);
|
||||
++it;
|
||||
}
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
|
||||
val.append(", ");
|
||||
appendJSONString(val, *it);
|
||||
appendJSONValue(val, *it);
|
||||
}
|
||||
val.append(" ]");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user