GSON序列化/反序列化
序列化-組合的過程
假設有個class是UserInfo,要把資料組合成Json字串
public class UserInfo{
String name;
String email;
int age;
public UserInfo(String name, String email, int age){
this.name = name;
this.email = email;
this.age = age;
}
}//1.建立物件
UserInfo userinfo = new UserInfo("Joe", "yoyo840821@icloud.com", 24);
//2. 建立gson物件
Gson gson = new Gson()
String jsonStr = gson.toJson(userinfo);
反序列化-解析的過程
有個json字串,要把它解析某個Java class
Last updated
Was this helpful?