Fixed some issues with empty values in JSON::Value::toString()

This commit is contained in:
Thulinma 2012-05-01 14:42:52 +02:00
parent 663ffb74eb
commit 332f399067

View file

@ -321,9 +321,11 @@ std::string JSON::Value::toString(){
} }
case ARRAY: { case ARRAY: {
std::string tmp = "["; std::string tmp = "[";
for (ArrIter it = ArrBegin(); it != ArrEnd(); it++){ if (arrVal.size() > 0){
tmp += it->toString(); for (ArrIter it = ArrBegin(); it != ArrEnd(); it++){
if (it + 1 != ArrEnd()){tmp += ",";} tmp += it->toString();
if (it + 1 != ArrEnd()){tmp += ",";}
}
} }
tmp += "]"; tmp += "]";
return tmp; return tmp;
@ -331,12 +333,14 @@ std::string JSON::Value::toString(){
} }
case OBJECT: { case OBJECT: {
std::string tmp2 = "{"; std::string tmp2 = "{";
ObjIter it3 = ObjEnd(); if (objVal.size() > 0){
--it3; ObjIter it3 = ObjEnd();
for (ObjIter it2 = ObjBegin(); it2 != ObjEnd(); it2++){ --it3;
tmp2 += "\"" + it2->first + "\":"; for (ObjIter it2 = ObjBegin(); it2 != ObjEnd(); it2++){
tmp2 += it2->second.toString(); tmp2 += "\"" + it2->first + "\":";
if (it2 != it3){tmp2 += ",";} tmp2 += it2->second.toString();
if (it2 != it3){tmp2 += ",";}
}
} }
tmp2 += "}"; tmp2 += "}";
return tmp2; return tmp2;