前提是String的格式是map或json类型的
public static void main(String[] args) {
Map<String,Object> map = new HashMap<String,Object>();
Map<String,String> mapNew = new HashMap<String,String>();
map.put("1", 11);
map.put("2", 22);
map.put("3", 33);
map.put("4", 44);
for (String string : map.keySet()) {
mapNew.put(string, map.get(string).toString());
} JSONObject jsonObject=JSONObject.fromObject(mapNew); String string = jsonObject.toString();
System.out.println(string); JSONObject jasonObject = JSONObject.fromObject(string);
Map<String,Object> map1 = (Map<String,Object>)jasonObject;
for (String s : map1.keySet()) {
System.out.println("s:"+map.get(s).toString());
}
}