String satusString = "{\"123\":\"zl\",\"456\":\"18\",\"789\":\"girl\",\"101\":\"5997\",\"102\":\"xxx\"}";
String[] split = satusString.split("\\{|\\}|,|\"|:");
Map<String, String> map = new HashMap<String, String>();
int n = 0;
String temp = "";
for (int i = 0; i < split.length; i++) {
if ((!split[i].equals("")) && split[i] != null) {
n++;
if (n == 1) {
temp = split[i];
map.put(temp, "");
} else {
map.put(temp, split[i]);
n = 0;
}
}
}
System.out.println(map);
输出结果为{123=zl, 101=5997, 102=xxx, 456=18, 789=girl}
本文介绍了一种使用Java将JSON格式的字符串解析并转换成Map集合的方法。通过字符串分割和Map的put操作,实现了键值对的有效存储,最终输出了包含123=zl,101=5997等键值对的Map集合。
4万+

被折叠的 条评论
为什么被折叠?



