Json转Map 多层结构
// json转map 多层结构type 1 ,多级转换; 2,多级拉平为一级;
public static Map<String, Object> jsonToMap(String str, int type)
throws JsonParseException, JsonMappingException, IOException {
Map<String, Object> resultmap = new HashMap<String, Object>();
if (type == 1) {
resultmap = (Map<String, Object>)JSON.parseObject(str);
} else if (type == 2) {
JSONObject jomap = JSONObject.parseObject(str);
for (Map.Entry<String, Object> Object : jomap.entrySet()) {
String key = Object.getKey();
Object value = Object.getValue();
if (value instanceof Map) {
resultmap.putAll(jsonToMap(String.valueOf(value),2));
} else {
resultmap.put(key, value);
}
}
}
return resultmap;
}
map转xml 多层结构
public static String getXmlByMap(Map