public static Map<String, String> result2map(String result) {
        String[] jsonarray = result.replace("{", "").replace("}", "").replaceAll("[\\n]", "")
            .split(",");
        Map<String, String> json = new HashMap<String, String>();
        for (String item : jsonarray) {
            String[] keyvalue = item.split("\":");
            json.put(keyvalue[0].replaceAll("\"", "").trim(), keyvalue[1].replaceAll("\"", "")
                .trim());
        }
        return json;
    }

解决方案 »

  1.   

    看样子是手动处理了一个JsonString转成了map醉了。。为啥要这么干
      

  2.   

    public static Map<String, String> result2map(String result) {
            // 将result中的{去掉,}去掉,\n去掉,之后按“,”切割成数组
            String[] jsonarray = result.replace("{", "").replace("}", "").replaceAll("[\\n]", "").split(",");
            // new个map
            Map<String, String> json = new HashMap<String, String>();
            // 迭代数组
            for (String item : jsonarray) {
                // 按":切割成数组
                String[] keyvalue = item.split("\":");
                // 将数组的第0个"去掉并去空格,第1个"去掉并去空格
                json.put(keyvalue[0].replaceAll("\"", "").trim(), keyvalue[1].replaceAll("\"", "").trim());
            }
            return json;
        }
      

  3.   


    public static Map<String, String> result2map(String result) {
            String[] jsonarray = result.replace("{", "").replace("}", "").replaceAll("[\\n]", "")
                .split(",");//把result字符串中的{ }和换行符去除掉,然后通过‘,’分割放到jsonarray数组中
            Map<String, String> json = new HashMap<String, String>();
            for (String item : jsonarray) {
                String[] keyvalue = item.split("\":");//把数组里的值按‘":’分割后放到keyvalue数组中
                json.put(keyvalue[0].replaceAll("\"", "").trim(), keyvalue[1].replaceAll("\"", "")
                    .trim());//replaceAll("\"", "")去除‘"’;然后把keyvalue[0]做key,keyvalue[1]做value放到map里
            }
            return json;
        }
      

  4.   

    我跟二楼想的一样为啥 要把json   传到服务器? - - 。真是醉了。  难道还需要解析吗。
    我做过一种就是  产品ID,数量 -产品ID,数量  这样拆分用的 但是你这一个真不知道
      

  5.   


    阿里云上  设备验证要json格式的         
      我也很迷糊
      

  6.   

    多谢!能不能再帮忙看下这段代码?
        private static String getStreamAsString(InputStream stream, String charset) throws IOException {
            try {
                Reader reader = new InputStreamReader(stream, charset);
                StringBuilder response = new StringBuilder();//StringBuilder能对字符串修改的类            final char[] buff = new char[1024];
                int read = 0;
                while ((read = reader.read(buff)) > 0) {
                    response.append(buff, 0, read);
                }            return response.toString();
            } finally {
                if (stream != null) {
                    stream.close();
                }
            }
        }