RIP*_*Sys 3 java json jackson gson
这是我正在尝试解析的HashMap:
HashMap map = new HashMap();
map.put("bowser", "b=mozilla");
map.put("car", "car=Ford");
map.put("model","model=Mustang");
map.put("Year", 2014);
map.put("dealer", "Dealer=AKHI");
Run Code Online (Sandbox Code Playgroud)
首先我尝试了Gson,然后是Jackson,但他们都有一个共同的问题.他们将"="解析为"\ u003d"
ObjectMapper mapper = new ObjectMapper();
try {
String json = mapper.writeValueAsString(map);
System.out.println("---------------------Parsed HashMap---------------------------:"+json);
}
catch (JsonGenerationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出是:
--------------------- Parsed HashMap --------------------------- :{"经销商":"Dealer\u003dAKHI","car":"car\u003dFord","Year":2014,"model":"model\u003dMustang","bowser":"b\u003dmozilla"}
我已经浏览了很少的其他博客,并发现API中存在一个小问题,但是我们可以通过其他方法解决这个问题.
该=标志编码为\u003d.因此你需要使用disableHtmlEscaping().
您可以使用
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
372 次 |
| 最近记录: |