Java Map to Json toJson(Map map)

Here you can find the source of toJson(Map map)

Description

join map

License

Apache License

Parameter

Parameter Description
map a parameter

Declaration

public static String toJson(Map<String, String> map) 

Method Source Code

//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();
    }
}

Related

  1. mapToJson(Map map)
  2. mapToJson(Map map, boolean pretty, String indent)
  3. mapToJson(Map parameters)
  4. mapToJson(Map map)
  5. toJSON(Map map)
  6. toJSON(Map map)
  7. toJSON(Map map)
  8. toJSONString(Map map, int indentLevel)