【Java】Map

遍历

String insertKeyStr = "";
String insertValStr = "";
Integer i = 0;
for (Object key : map.keySet()) {
    Object value = map.get(key);
    insertKeyStr += key + ", ";
    insertValStr += "\"" + value + "\", ";
    if ( i < map.keySet().size() - 1 ) {
        insertKeyStr += ",";
        insertValStr += ",";
    }
    i++;
}

map转json

import com.alibaba.fastjson.JSONObject;

Map<String, Object> toDataMap = new HashMap<>();
JSONObject jsonData = new JSONObject(toDataMap);
String toJSONString = jsonData.toJSONString();
posted @ 2022-11-23 10:21  小魁jking  阅读(24)  评论(0编辑  收藏  举报