接下来将使用GSON作为本项目的JSON解析器

This commit is contained in:
Kirigaya Kazuto 2017-03-07 12:36:23 +08:00
parent a428abe334
commit 7c8bfad30f

53
JsonStudy.java Normal file
View File

@ -0,0 +1,53 @@
import com.google.gson.Gson;
class RegisterData
{
private String email;
private String nickname;
private String pwass;
private String school;
public String getEmail()
{
return email;
}
public void setEmail(String Email)
{
email=Email;
}
public String getNickname()
{
return nickname;
}
public void setNickname(String Nickname)
{
nickname=Nickname;
}
public String getPass()
{
return pwass;
}
public void setPass(String Pwass)
{
pwass=Pwass;
}
public String getSchool()
{
return school;
}
public void setSchool(String School)
{
school=School;
}
}
public class JsonStudy
{
public static void main(String[] args)
{
String jsonData="{'email':'test@163.com','nickname':'Kirito','school':'QUST','pwass':'dvaLovesU'}";
Gson gson=new Gson();
RegisterData data=gson.fromJson(jsonData, RegisterData.class);
System.out.println("Email:"+data.getEmail()+" NickName:"+data.getNickname()+" School:"+data.getSchool()+" Password:"+data.getPass());
}
}