0
たこんにちは、私は私のアプリに自分のREST APIからの変更履歴のリストを作成しようとしていますが、私はここに、このエラーラインのいくつかの問題を持っている:期待BEGIN_ARRAYしかしBEGIN_OBJECT JSON
期待BEGIN_ARRAYが、行1列でBEGIN_OBJECTました2パス$
JSON出力:
{
"forced": "true",
"version": "1.0A(125)",
"description": [
{
"description": "Fixed some things 1"
},
{
"description": "Fixed some things 2"
},
{
"description": "Fixed some things 3"
},
{
"description": "Fixed some things 4"
}
]
}
マイRESTコール:
@GET("updatecheck")
Observable<List<UpdateCheckResponse>> UpdateCheckChangeLog();
は、ここに私のPOJOクラスは名前が付けられ:UpdateCheckResponse.java
public class UpdateCheckResponse {
@SerializedName("forced")
@Expose
private String forced;
@SerializedName("version")
@Expose
private String version;
@SerializedName("description")
@Expose
private List<UpdateCheckDescription> description = null;
public String getForced() {
return forced;
}
public void setForced(String forced) {
this.forced = forced;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public List<UpdateCheckDescription> getDescription() {
return description;
}
public void setDescription(List<UpdateCheckDescription> description) {
this.description = description;
}
}
という名前の私のPOJO:UpdateCheckDescription.java
public class UpdateCheckDescription {
@SerializedName("description")
@Expose
private String description;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
UpdateChangeLogAdapter.class
public class UpdateChangeLogAdapter extends RecyclerView.Adapter<UpdateChangeLogAdapter.ViewHolder> {
private ArrayList<UpdateCheckDescription> mAndroidList;
public UpdateChangeLogAdapter(ArrayList<UpdateCheckDescription> androidList) {
mAndroidList = androidList;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_update, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.mTvChangelog.setText(mAndroidList.get(position).getDescription());
}
@Override
public int getItemCount() {
return mAndroidList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
private TextView mTvChangelog;
public ViewHolder(View view) {
super(view);
mTvChangelog = (TextView)view.findViewById(R.id.descriptionTextView);
}
}
}
そして、ここでは私のUpdateActivityからの呼び出しですクラス:
private void loadJSON() {
FitnessM8REST apiService =
FitnessM8RestClient.getClient().create(FitnessM8REST.class);
mCompositeDisposable.add(apiService.UpdateCheckChangeLog()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(this::handleResponse,this::handleError));
}
private void handleResponse(List<UpdateCheckResponse> androidList) {
mAndroidArrayList = new ArrayList<>(androidList);
mAdapter = new UpdateChangeLogAdapter(mAndroidArrayList);
mRecyclerView.setAdapter(mAdapter);
}
private void handleError(Throwable error) {
Toast.makeText(this, "Error "+error.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
Log.d("Error: ", error.getLocalizedMessage());
}
エラーメッセージはわかりやすいものです。応答でJSON配列が必要だと言ったが、代わりにJSONオブジェクトを受け取った。 –
これを確認してください:https://stackoverflow.com/a/38351872/6021469 –