Here you can find the source of mapToJson(Map
public static String mapToJson(Map<String, String> map)
//package com.java2s; import java.util.Map; public class Main { public static String mapToJson(Map<String, String> map) { StringBuffer json = new StringBuffer("{"); int index = 0; for (String key : map.keySet()) { if (index > 0) { json.append(","); }/* w w w . j a v a2 s . c o m*/ json.append("'" + key + "':'" + map.get(key) + "'"); index++; } json.append("}"); return json.toString(); } }