我是新手来改进 xml解析并遵循 xml解析的教程。但结果没有显示,经过调试后我发现onresponse
没有被调用。
我试图通过onFailure
找出,但是因为无法构造内部类而得到错误。
这是界面
public interface MapAPI {
@GET("/dealer")
Call<ApiResponse> getList(@Query("zip") String zip);
}
这是API响应类。
@Root(name = "dealers", strict = false)
public class ApiResponse {
@ElementList(inline = true)
public List<Dealer> dealerList;
@Root(name = "dealer")
public class Dealer {
@Element(name = "name")
private String name;
@Element(name = "google_static_map_url")
private String staticMapUrl;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStaticMapUrl() {
return staticMapUrl;
}
public void setStaticMapUrl(String staticMapUrl) {
this.staticMapUrl = staticMapUrl;
}
}
}
代码activity
private void getDealerList() {
Retrofit retrofit = new Retrofit.Builder().baseUrl(API_BASE_URL).client(new OkHttpClient()).addConverterFactory(SimpleXmlConverterFactory.create()).build();
MapAPI dealerApiKey = retrofit.create(MapAPI.class);
Call<ApiResponse> callResponse = dealerApiKey.getList("55082");
callResponse.enqueue(new Callback<ApiResponse>() {
@Override
public void onResponse(Call<ApiResponse> call, Response<ApiResponse> mResponse) {
mDealerList = mResponse.body().dealerList;
ArrayList<Dealer> dealerArrayList = new ArrayList<>(mDealerList);
adapter = new StoreListAdapter(dealerArrayList, getApplicationContext());
mRecyclerView.setAdapter(adapter);
}
}
}
有人可以告诉我我正在做的错误吗?