【发布时间】:2015-07-10 08:27:46
【问题描述】:
我在 MainActivity 中创建了在按下刷新按钮时调用的函数
public void callWeatherAPI(){
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
final String strUserName = SP.getString("username", "NA");
int defaultval = Integer.parseInt(strUserName);
WeatherAPI weatherAPI = APIHandler.getApiInterface();
weatherAPI.getWeatherCity(defaultval, new Callback<StudentData>() {
public void success(final StudentData arg0, Response arg1) {
Toast.makeText(getApplicationContext(), arg0.getStudentName(), Toast.LENGTH_LONG).show();
// Toast.makeText(getApplicationContext(), WeatherData.getWeatherCity().getDescription(), Toast.LENGTH_LONG).show();
}
public void failure(RetrofitError arg0) {
Toast.makeText(getApplicationContext(), "OPS, some kind of problem had happend! :(", Toast.LENGTH_LONG).show();
}
});
}
}
并在 MainActivity 中创建了一个静态类
public static class Student{
public String exam_roll;
public String class_no;
public String block_no;
public String name;
}
public static class StudentData{
Student student;
public int success;
public int getStudentName() {
return success;
}
}
json是谁的
{"success":1,"student":[{"exam_roll":"1212","class_no":"121","block_no":"1221","name":"rohit"}]}
我已将回调函数设置为指向 StudentData 类
public interface WeatherAPI {
//@GET("/weather")
@GET("/")
void getWeatherCity(@Query("pid") int pid, Callback<MainActivity.StudentData> callback);
}
不知道这是什么问题,它返回改造错误函数
改造的错误是
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 25
【问题讨论】: