Here you can find the source of toJson(Map
Parameter | Description |
---|---|
map | a parameter |
public static String toJson(Map<String, String> map)
//package com.java2s; //License from project: Apache License import java.util.Iterator; import java.util.Map; public class Main { /**/*from w ww . j av a 2s . c om*/ * join map * @param map * @return */ public static String toJson(Map<String, String> map) { if (map == null || map.size() == 0) { return null; } 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(); } }