java json 四个格式

java 官方
<dependency>
  <groupId>org.json</groupId>
  <artifactId>json</artifactId>
  <version>20220320</version>
</dependency>
  • code
JSONObject jsonObject = new JSONObject();
jsonObject.put("secretKey", secretKey);
jsonObject.put("appKey", appKey);
System.out.println("JSON JAVA       :" + jsonObject + "\n");
google gson
<dependency>
  <groupId>com.google.code.gson</groupId>
  <artifactId>gson</artifactId>
  <version>2.8.9</version>
</dependency>
  • code
Gson gson = new Gson();
System.out.println("GSON GOOGLE     :" + gson.toJson(enInforMap) + "\n");
alibaba fastjson
<dependency>
   <groupId>com.alibaba</groupId>
  <artifactId>fastjson</artifactId>
  <version>1.2.67_noneautotype2</version>
</dependency>
  • code
com.alibaba.fastjson.JSONObject fastJsonObject = new com.alibaba.fastjson.JSONObject();
fastJsonObject.put("secretKey", secretKey);
fastJsonObject.put("appKey", appKey);
System.out.println("FASTJSON ALIBABA :" + fastJsonObject + "\n");
jackjson FasterXML
<dependency>
     <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>2.12.7.1</version>
</dependency>
  • code
ObjectMapper objectMapper = new ObjectMapper();
System.out.println("JACKSON FasterXML  :" + objectMapper.writeValueAsString(enInforMap) + "\n");
posted @ 2023-04-17 11:00  vx_guanchaoguo0  阅读(43)  评论(0编辑  收藏  举报