从外部源获取JSON并尝试使用GSON解析它,我得到了上面提到的错误。这是我的主要活动:
final ProgressDialog dialog;
dialog = new ProgressDialog(PlayerDetailsActivity.this);
dialog.setTitle(getString(R.string.string_getting_json_title));
dialog.setMessage(getString(R.string.string_getting_json_message));
dialog.show();
ApiService api = RetroClient.getApiService();
Call<PlayerRolesList> call = api.getMyJSON();
call.enqueue(new Callback<PlayerRolesList>() {
@Override
public void onResponse(Call<PlayerRolesList> call, Response<PlayerRolesList> response) {
//Dismiss Dialog
dialog.dismiss();
if(response.isSuccessful()) {
/**
* Got Successfully
*/
Toast.makeText(PlayerDetailsActivity.this, "Successful", Toast.LENGTH_LONG).show();
alPlayerRoles = response.body().getPlayerRoles();
/**
* Binding that List to Adapter
*/
adapter = new PlayerDetailsAdapter(PlayerDetailsActivity.this, alPlayerRoles);
lvPlayerRoles.setAdapter(adapter);
} else {
Toast.makeText(PlayerDetailsActivity.this, response.message(), Toast.LENGTH_LONG).show();
}
}
这是发出请求的代码,并且应该使用适配器填充布局。
这也是模型类:
public class PlayerRolesList {
@SerializedName("data")
@Expose
private ArrayList<PlayerRolesModel> players = new ArrayList<>();
/**
* @return The contacts
*/
public ArrayList<PlayerRolesModel> getPlayerRoles() {
return players;
}
/**
* @param players The player roles
*/
public void setPlayerRoles(ArrayList<PlayerRolesModel> players) {
this.players = players;
}
}
我根据本教程http://www.pratikbutani.com/2016/05/android-tutorial-json-parsing-using-retrofit-part-1/
完成了整个过程运行他的应用程序工作正常,但由于某些原因我的似乎不同意JSON,我不确定我在哪里犯错误。
此错误消息的常见原因是什么?