1、依赖jar包
gson-2.7.jar
2、调用方法:
Gson gson = new Gson();
String json = gson.toJson(user,UserEntity.class);
UserEntity user = new UserEntity();
user.setId(10);
user.setName("蔡晨力");
public class UserEntity {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
网友评论