Map.toString()后字符串转换回Map

       public static void main(String[] args) {
		String str="{attach=  sfsd  , sub_mch_id=10000100, time_end=20140903131540, openid=oUpF8uMEb4qRXf22hE3X68TekukE, bank_type=CFT, return_code=SUCCESS}";
		Map<String,String> map=mapStringToMap(str);
	}
	
	public static Map<String,String> mapStringToMap(String str){
		str=str.substring(1, str.length()-1);
		String[] strs=str.split(",");
		Map<String,String> map = new HashMap<String, String>();
		for (String string : strs) {
			String key=string.split("=")[0];
			String value=string.split("=")[1];
			map.put(key, value);
		}
		return map;
	}

你可能感兴趣的:(java,map)