stringify method output wrong json string #891

This commit is contained in:
Alex Fabijanic 2015-07-30 20:49:54 -05:00
parent 04caf94bb6
commit 08a85e84a4
2 changed files with 14 additions and 7 deletions

View File

@ -32,33 +32,35 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde
{
if (step == -1) step = indent;
if ( any.type() == typeid(Object) )
if (any.type() == typeid(Object))
{
const Object& o = any.extract<Object>();
o.stringify(out, indent == 0 ? 0 : indent, step);
}
else if ( any.type() == typeid(Array) )
else if (any.type() == typeid(Array))
{
const Array& a = any.extract<Array>();
a.stringify(out, indent == 0 ? 0 : indent, step);
}
else if ( any.type() == typeid(Object::Ptr) )
else if (any.type() == typeid(Object::Ptr))
{
const Object::Ptr& o = any.extract<Object::Ptr>();
o->stringify(out, indent == 0 ? 0 : indent, step);
}
else if ( any.type() == typeid(Array::Ptr) )
else if (any.type() == typeid(Array::Ptr))
{
const Array::Ptr& a = any.extract<Array::Ptr>();
a->stringify(out, indent == 0 ? 0 : indent, step);
}
else if ( any.isEmpty() )
else if (any.isEmpty())
{
out << "null";
}
else if ( any.isNumeric() || any.isBoolean() )
else if (any.isNumeric() || any.isBoolean())
{
out << any.convert<std::string>();
std::string value = any.convert<std::string>();
if (any.type() == typeid(char)) formatString(value, out);
else out << value;
}
else
{

View File

@ -322,6 +322,11 @@ void JSONTest::testStringProperty()
std::string value = test.convert<std::string>();
assert(value.compare("value") == 0);
object.set("test2", 'a');
std::ostringstream ostr;
object.stringify(ostr);
assert(ostr.str() == "{\"test\":\"value\",\"test2\":\"a\"}");
DynamicStruct ds = object;
assert (!ds["test"].isEmpty());
assert (ds["test"].isString());