Dies ist, wie meine JSON
Antwort siehtRetrofit Liste der Objekt zuweist null Daten
[
{
"id": 1,
"PhName": "sample string 2",
"Longitude": 3.1,
"Latitude": 4.1,
"ApplicationUserId": "sample string 5"
},
{
"id": 1,
"PhName": "sample string 2",
"Longitude": 3.1,
"Latitude": 4.1,
"ApplicationUserId": "sample string 5"
}
]
dies ist mein Retrofit-Schnittstelle Aufruf
@GET("/api/GPS")
@Headers({
"Accept: application/json"
})
Call<List<UserResponse>> search(@Query("search") String search,
@Header("Authorization") String auth);
Pojo Klasse
public class UserResponse {
@SerializedName("Id")
int id;
@SerializedName("UserName")
String phName;
@SerializedName("Longitude")
int lon;
@SerializedName("Latitude")
int lat;
@SerializedName("ApplicationUserId")
String appUserId;
//getters and setters
}
Retrofit Erklärung
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(PerformLogin.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
Daten abrufen und es
MyApiEndpointInterface apiService =
retrofit.create(MyApiEndpointInterface.class);
Call<List<UserResponse>> call = apiService.search(query,"Bearer "+token);
call.enqueue(new Callback<List<UserResponse>>() {
@Override
public void onResponse(Call<List<UserResponse>> call, Response<List<UserResponse>> response) {
List<UserResponse> userList = response.body();
Log.w("My App", response.message());
for (int i = 0; i <userList.size() ; i++) {
Log.w("My App", userList.get(i).getPhName()+""+i);
}
//mAdapter = new MyAdapter(getContext(),userList);
//mRecyclerView.setAdapter(mAdapter);
}
@Override
public void onFailure(Call<List<UserResponse>> call, Throwable t) {
Log.w("My App", t.getMessage());
}
});
meine Antwort
W/My App: OK
W/My App: null 0
W/My App: null 1
W/My App: null 2
W/My App: null 3
In diesem Fall bin ich nehme erhalten vier ergeben sich aus der Suche und die Namen geben mir null verwenden.
Gibt es irgendetwas, was ich falsch mache oder eine bessere Lösung?