Java examples for java.util:Map Entry
Convert Map<String, String> to Simple Json
//package com.java2s; import java.util.Iterator; import java.util.Map; public class Main { public static String toSimpleJson(Map<String, String> map) { if (map == null || map.size() == 0) { return null; }/*w w w . ja va 2 s. co m*/ StringBuilder paras = new StringBuilder(); paras.append("{"); Iterator<Map.Entry<String, String>> ite = map.entrySet().iterator(); while (ite.hasNext()) { Map.Entry<String, String> entry = (Map.Entry<String, String>) ite .next(); paras.append("\"").append(entry.getKey()).append("\":\"") .append(entry.getValue()).append("\""); if (ite.hasNext()) { paras.append(","); } } paras.append("}"); return paras.toString(); } }