From 63d83781180683c89f2eaedc8474eb0bbf0946c7 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 1 May 2012 14:42:52 +0200 Subject: [PATCH] Fixed some issues with empty values in JSON::Value::toString() --- util/json.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/util/json.cpp b/util/json.cpp index 37ce3279..2799c9f1 100644 --- a/util/json.cpp +++ b/util/json.cpp @@ -321,9 +321,11 @@ std::string JSON::Value::toString(){ } case ARRAY: { std::string tmp = "["; - for (ArrIter it = ArrBegin(); it != ArrEnd(); it++){ - tmp += it->toString(); - if (it + 1 != ArrEnd()){tmp += ",";} + if (arrVal.size() > 0){ + for (ArrIter it = ArrBegin(); it != ArrEnd(); it++){ + tmp += it->toString(); + if (it + 1 != ArrEnd()){tmp += ",";} + } } tmp += "]"; return tmp; @@ -331,12 +333,14 @@ std::string JSON::Value::toString(){ } case OBJECT: { std::string tmp2 = "{"; - ObjIter it3 = ObjEnd(); - --it3; - for (ObjIter it2 = ObjBegin(); it2 != ObjEnd(); it2++){ - tmp2 += "\"" + it2->first + "\":"; - tmp2 += it2->second.toString(); - if (it2 != it3){tmp2 += ",";} + if (objVal.size() > 0){ + ObjIter it3 = ObjEnd(); + --it3; + for (ObjIter it2 = ObjBegin(); it2 != ObjEnd(); it2++){ + tmp2 += "\"" + it2->first + "\":"; + tmp2 += it2->second.toString(); + if (it2 != it3){tmp2 += ",";} + } } tmp2 += "}"; return tmp2;