引入 Gson 到 pom.xml

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.5</version>
</dependency>

示例代码

JsonObject rest_data = new JsonObject();
rest_data.addProperty("id", 123);
rest_data.addProperty("name",  "shanghai");

Gson gson = new Gson();
String payload = gson.toJson(rest_data);

相关文章:

  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-05-27
  • 2021-12-11
猜你喜欢
  • 2021-10-17
  • 2022-12-23
  • 2021-06-22
  • 2022-01-12
  • 2021-05-21
  • 2021-12-07
相关资源
相似解决方案