Java-json对象转Map
String s = "{\"name\":\"zl\",\"age\":\"18\",\"sex\":\"girl\",\"number\":\"5997\",\"other\":\"xxx\"}";
String[] split = s.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;
}
}
}
测试结果:
{number=5997, other=xxx, sex=girl, name=zl, age=18}
网络上志同道合,我们一起学习网络安全,一起进步,QQ群:694839022