下面是我試圖分析我的JSON數組的字符串:爲什麼Gson庫在JSON解析中給我一個異常?
[{"Phone_Number":"-9463232156","Fax_Number":"-","EmailID":"[email protected]","Established_Year":"1995","Recognized_Year":"0","Recognized_Number":"0","Affilation_Board_10":"PSEB","Affilation_Board_12":"","IsSchool_Shifts":"No","Medium_Code":"Punjabi"}]
類BasicDetails.java
public class BasicDetails {
public String Phone_Number;
public String Fax_Number;
public String EmailID;
public String Established_Year;
public String Recognized_Year;
public String Recognized_Number;
public String Affilation_Board_10;
public String Affilation_Board_12;
public BasicDetails(String phone_Number, String fax_Number, String emailID, String established_Year, String recognized_Year, String recognized_Number, String affilation_Board_10, String affilation_Board_12, String isSchool_Shifts, String medium_Code) {
Phone_Number = phone_Number;
Fax_Number = fax_Number;
EmailID = emailID;
Established_Year = established_Year;
Recognized_Year = recognized_Year;
Recognized_Number = recognized_Number;
Affilation_Board_10 = affilation_Board_10;
Affilation_Board_12 = affilation_Board_12;
IsSchool_Shifts = isSchool_Shifts;
Medium_Code = medium_Code;
}
public String IsSchool_Shifts;
public String Medium_Code;
public String getPhone_Number() {
return Phone_Number;
}
public String getFax_Number() {
return Fax_Number;
}
public String getEmailID() {
return EmailID;
}
public String getEstablished_Year() {
return Established_Year;
}
public String getRecognized_Year() {
return Recognized_Year;
}
public String getRecognized_Number() {
return Recognized_Number;
}
public String getAffilation_Board_10() {
return Affilation_Board_10;
}
public String getAffilation_Board_12() {
return Affilation_Board_12;
}
public String getIsSchool_Shifts() {
return IsSchool_Shifts;
}
public String getMedium_Code() {
return Medium_Code;
}
}
類BasicDetailsList.java
public class BasicDetailsList {
public List<BasicDetails> basicDetailsArrayList;
public List<BasicDetails> getBasicDetailsArrayList() {
return basicDetailsArrayList;
}
public void setBasicDetailsArrayList(List<BasicDetails> basicDetailsArrayList) {
this.basicDetailsArrayList = basicDetailsArrayList;
}
public BasicDetailsList() {
basicDetailsArrayList = new ArrayList<BasicDetails>();
}
}
以下是代碼,我我正在使用解析。 字符串變量r包含JSON數組
Gson gson=new GsonBuilder().create();
BasicDetailsList basicDetailsList=gson.fromJson(r,BasicDetailsList.class);
estd.setText(basicDetailsList.basicDetailsArrayList.get(0).Established_Year);
phone.setText(basicDetailsList.basicDetailsArrayList.get(0).Phone_Number);
fax.setText(basicDetailsList.basicDetailsArrayList.get(0).Fax_Number);
email.setText(basicDetailsList.basicDetailsArrayList.get(0).EmailID);
affiliation.setText(basicDetailsList.basicDetailsArrayList.get(0).Affilation_Board_10);
medium.setText(basicDetailsList.basicDetailsArrayList.get(0).Medium_Code);
什麼是錯誤? –
請提供logcat –
com.google.gson.jsonsyntax例外 –