Ejemplo n.º 1
0
string JSONUtil::getDocumentStr(const JSONElement& doc)
{
	string jsonText;
	if(doc.getType()==JSONElement::JSON_OBJECT)
		jsonText += "{";
	else
		jsonText += "[";
	if(doc.hasChildren())
	{
		for (int var = 0; var < (int)doc.getChildren().size(); ++var) {
			JSONElement* child = doc.getChildren().at(var);
			if(doc.getType()==JSONElement::JSON_OBJECT)
				jsonText += "\"" + child->getName() + "\":";
			if(child->getType()==JSONElement::JSON_OBJECT || child->getType()==JSONElement::JSON_ARRAY)
			{
				jsonText += getDocumentStr(*child);
			}
			else
			{
				if(child->getType()==JSONElement::JSON_STRING)
					jsonText += "\"" + child->getValue() + "\"";
				else
					jsonText += child->getValue();
			}
			if(var!=(int)doc.getChildren().size()-1)
			{
				jsonText += ", ";
			}
		}
	}
	if(doc.getType()==JSONElement::JSON_OBJECT)
		jsonText += "}";
	else
		jsonText += "]";
	return jsonText;
}