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}
posted @ 2017-07-13 18:16  SEC.VIP_网络安全服务  阅读(83)  评论(0编辑  收藏  举报