I have a JSON array without any object(key) inside which there are JSON Objects like this :
[ 137, 80, 78, 71, 13, 10, 26, 10 ]
I tried to parse it but can't find success can anyone suggest me how to parse this type of Response using Retrofit?
Till now what I am done is in the Activity I have done like:-
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Api.BASE_URL)
.addConverterFactory(GsonConverterFactory.create()) //Here we are using the GsonConverterFactory to directly convert json data to object
.build();
Api api = retrofit.create(Api.class);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("userName", "none\\\\Android");
Call call = api.getUserIcon(jsonObject);
// Displaying the user a loader with the specific message
dialog.setMessage("Loading... Please wait...");
dialog.show();
call.enqueue(new Callback<Integer>() {
@Override
public void onResponse(Call<Integer> call, Response<Integer> response) {
if (response.isSuccessful()) {
if (dialog.isShowing())
dialog.dismiss();
} else {
if (dialog.isShowing())
dialog.dismiss();
// if successfully not added
Toast.makeText(getActivity(), "Failure in Success Response", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<Integer> call, Throwable t) {
if (dialog.isShowing())
dialog.dismiss();
Toast.makeText(getActivity(), "Failure in Parsing", Toast.LENGTH_SHORT).show();
}
});
and in the interface I have:-
@Headers({
"Content-Type:application/json; charset=utf-8",
"Content-Encoding:UTF-8",
"Authorization:Basic bnhvbmVcS2Fua2FTZW46NllrKkNpezc=",
"appID:Sample Android App",
"locale:en-US"
})
@POST("Admin/GetRegisteredUserIcon")
Call<List<Integer>> getUserIcon(
@Body JsonObject body);