我想了解每一個我的回答是失敗的時候,我是如何工作的改進,但即使使用GitHub的API,但仍然是我的響應失敗了,我做錯了什麼 我很困惑改造響應失敗
鏈接
http://api.openweathermap.org/data/2.5/weather?q=Spakane,Us&appid=api_key
接口類
@GET("data/2.5/weather")
Call<List<Weather>> getWeatherData(@Query("q") String cityName,@Query("appid") String apikey);
MainActivity
private final String BASE_URL = "http://api.openweathermap.org/";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
RestApi api = retrofit.create(RestApi.class);
final Call<List<Weather>> weather = api.getWeatherData("rawalpindi",API_KEY);
final ProgressDialog pg = new ProgressDialog(this);
pg.setTitle("Downloading");
pg.setMessage("Please Wait .....");
pg.show();
weather.enqueue(new Callback<List<Weather>>() {
@Override
public void onResponse(Call<List<Weather>> call, Response<List<Weather>> response) {
pg.dismiss();
Log.d(TAG, "onResponse: "+response.isSuccessful());
Log.d(TAG, "onResponse: "+response.body().get(0).getClouds());
}
@Override
public void onFailure(Call<List<Weather>> call, Throwable t) {
Log.d(TAG, "onFailure: Failed :(");
Log.d(TAG, "onResponseFailed: "+call.request().url());
pg.dismiss();
}
});
登錄
D/MainActivity: onFailure: Failed :(
D/MainActivity: onResponseFailed: http://api.openweathermap.org/data/2.5/weather?q=rawalpindi&appid=api_key
拋出消息
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
打印拋出錯誤消息通過問題得到.. –
這是拋出的消息「」預期BEGIN_ARRAY但BEGIN_OBJECT位於第1個第2列路徑$「」 – Salman500
的[2改造Android的預期BEGIN ARRAY可能重複但BEGIN OBJECT在第1行第2列](https://stackoverflow.com/questions/36177629/retrofit2-android-expected-begin-array-but-was-begin-object-at-line-1-column-2) –