1、使用fastjson
1.1、添加Maven依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.54</version>
</dependency>
1.2、对象转字符串
Ticket ticket =new Ticket();
ticket.setTicketTypeId("1234");
JSONObject.toJSONString(ticket)
(1)、注意,这个地方默认生成的json字符串会将变量第一个字符串小写了,要解决这个问题,需要在对象中使用@JSONField(name = "TicketTypeId")
参考文档:https://www.cnblogs.com/mao2080/p/6909160.html
public class Ticket {
@JSONField(name = "TicketTypeId")
private String TicketTypeId;
@JSONField(name = "RequestingUser_Id")
private String RequestingUser_Id;
@JSONField(name = "TransactorUser_Id")
private String TransactorUser_Id;
网友评论