试了一下,json串多字段或少字段都可以解析不会报错
UserRegisterInfo regResp1 = new Gson().fromJson(resp1,UserRegisterInfo.class);
public class UserRegisterInfo {
private String error_code;
private String error_msg;
private String user_id;
private String card_no;
}
1.String resp1 = "{\"error_code\":\"0000\",\"error_msg\":\"122\",\"user_id\":\"122\",\"aa\":\"122\"}";
UserRegisterInfo regResp1 = new Gson().fromJson(resp1,UserRegisterInfo.class);
输出:UserRegisterInfo(error_code=null, error_msg=122, user_id=122, card_no=null)
2. String resp1 = "{\"error_code\":\"0000\",\"error_msg\":\"122\",\"user_id\":\"122\",\"card_no\":\"122\",\"aa\":\"122\"}";
输出:UserRegisterInfoResponse(error_code=0000, error_msg=122, user_id=122, card_no=122)
3.
String resp1 = "{\"error_code\":\"0000\",\"error_msg\":\"122\",\"user_id\":\"122\"}";
输出:UserRegisterInfoResponse(error_code=0000, error_msg=122, user_id=122, card_no=122)
UserRegisterInfoResponse(error_code=0000, error_msg=122, user_id=122, card_no=null)