StringBuffer returnJSON = new StringBuffer("\r\n{\"" + title + "\":{");
String key = "";
String value = "";
// loop through all the map entries.
Iterator it = map.entrySet().iterator();
while (it.hasNext())
{
Map.Entry e = (Map.Entry) it.next();
value = (String) e.getValue();
key = (String) e.getKey();
returnJSON.append("\r\n\"" + key + "\": \"" + value + "\",");
}
// remove the last comma
int lastCharIndex = returnJSON.length();
returnJSON.deleteCharAt(lastCharIndex - 1);
returnJSON.append("\r\n}}");
return returnJSON.toString();