通过Map生成一个json字符串

@param map 需要转换的map
@return json串
764311
public static String toJson(Map<String, Object> map) {
        requireNonNull(map, "map is null");
        return JSON.toJSONString(map, DEFAULT_FORMAT);
    }
871192
public static String asString(Map<?, ?> map) {
        if (map == null) {
            return NULL;
        }
        StringBuilder builder = new StringBuilder();
        builder.append('{');
        boolean first = true;
        for (Map.Entry<?, ?> entry : map.entrySet()) {
            if (first) {
                first = false;
            } else {
                builder.append(',');
            }
            builder.append(asString(entry.getKey()))
                   .append(':')
                   .append(asString(entry.getValue()));
        }
        builder.append('}');
        return builder.toString();
    }
988660
public static Object[][] toObjectArray(Map<?, ?> map) {
		if(map == null) {
			return null;
		}
		final Object[][] result = new Object[map.size()][2];
		if(map.isEmpty()) {
			return result;
		}
		int index = 0;
		for(Entry<?, ?> entry : map.entrySet()) {
			result[index][0] = entry.getKey();
			result[index][1] = entry.getValue();
			index++;
		}
		return result;
	}
1193470
public String toJson(Map<?, ?> map) {
    StringWriter stringWriter = new StringWriter();
    try {
      toJson(map, stringWriter);
    } catch (IOException e) {
      throw new AssertionError(e); // No I/O writing to a Buffer.
    }
    return stringWriter.toString();
  }
575751
public static String propertiesToString(Map<String,Object> map)
    {
        String strProperties = null;
        Properties properties = Utility.mapToProperties(map);
        ByteArrayOutputStream baOut = new ByteArrayOutputStream();
        try   {
            properties.store(baOut, PROPERTIES_COMMENT);
            byte[] rgBytes = baOut.toByteArray();
            ByteArrayInputStream baIn = new ByteArrayInputStream(rgBytes);
            InputStreamReader isIn = new InputStreamReader(baIn); // byte -> char
            char[] cbuf = new char[rgBytes.length];
            isIn.read(cbuf, 0, rgBytes.length);
            if (cbuf.length == rgBytes.length)
                strProperties = new String(cbuf);
        } catch (IOException ex)    {
            ex.printStackTrace();
        }
        return strProperties;
    }
866288
@SuppressWarnings("unchecked")
    public M newInstance(final Map<String, V> map) {
        return (M) new MapMessage<>(map);
    }
922017
public static Map<String, String> serialize(Map<String, Object> map, String prefix) {
        if (map == null || map.isEmpty()) {
            return Collections.emptyMap();
        }

        Map<String, String> flattened = flatten(map, new HashMap<String, String>(), new ArrayList<String>());

        Map<String, String> result = new HashMap<>();
        for (Map.Entry<String, String> entry : flattened.entrySet()) {
            result.put(prefix + "." + entry.getKey(), entry.getValue());
        }

        return result;
    }
971620
public static <K, V> Map<K, V> cast(Map<?, ?> map) {
    return map == null ? null : new CastingMap<K, V>(map);
  }
412012
public static void jsonMap(JsonWriter writer, Map<String, Object> map) throws IOException {
        if (map != null) {
            writer.beginObject();
            jsonMapEntries(writer, map);
            writer.endObject();
        }
    }
563143
private Map<String, Object> getMapFromJSON(String json) {
        Map<String, Object> propMap = new HashMap<String, Object>();
        ObjectMapper mapper = new ObjectMapper();

        // Initialize string if empty
        if (json == null || json.length() == 0) {
            json = "{}";
        }

        try {
            // Convert string
            propMap = mapper.readValue(json, new TypeReference<HashMap<String, Object>>(){});
        } catch (Exception e) {
            ;
        }
        return propMap;
    }
540480
public static String serializeMap(Map<String, String> map) {
        if (map == null) {
            map = new HashMap<String, String>();
        }
        XStream xstream = new XStream(new DomDriver());
        return xstream.toXML(map);
    }
845380
public static Mapper mapMapper(final Map map) {
        return new Mapper() {
            public Object map(final Object a) {
                return map.get(a);
            }
        };
    }
1206861
public static Map<String, Object> generateMap(InputStream inputStream) {
        logger.trace("Converting XML document [{}]");
        Map<String, Object> map = asMap(inputStream);

        logger.trace("Generated JSON: {}", map);
        return map;
    }
1004124
public static String mapToString(Map<String, ?> map) {
        StringBuilder sb = new StringBuilder();
        sb.append("{\n");
        for (String key : map.keySet()) {
            if (map.get(key) != null) {
                sb.append(key + ": " + map.get(key) + "\n ");
            } else {
                continue;
            }
        }
        sb.append("}");
        return sb.toString();
    }
712546
public static Map<String, Object> jsonObjectToMap(JSONObject jsonObj)
    {
        Map<String, Object> map = new Hashtable<String, Object>();
        
        Iterator<?> iterator = jsonObj.keys();
        while (iterator.hasNext())
        {
            try {
                String key = (String)iterator.next();
                String value = jsonObj.getString(key);  // TODO what if this is a JSONObject?
                map.put(key, value);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return map;
    }
992915
public void serialize(Map<String, T> map, OutputStream os) throws IOException {
        JsonGenerator jsonGenerator = LoganSquare.JSON_FACTORY.createGenerator(os);
        serialize(map, jsonGenerator);
        jsonGenerator.close();
    }
1131849
public static ValueMap map(Object... map) {
        if (map.length / 2 * 2 != map.length)
            throw new IllegalArgumentException("Arguments should be <String> key - <?> value pairs");

        Builder builder = new Builder();
        for (int i = 0; i < map.length; i += 2)
            builder.put((String)map[i], map[i + 1]);

        return builder.build();
    }