Мне нужно проанализировать массив JSON из «Дооснащения». Мне нужно, чтобы получить следующий ключ:Получите массив JSON из retrofit Response
{
"rc":0,
"message":"success",
"he":[
{
"name":"\u05de\u05e4\u05e7\u05d7",
"type":0
}
]
}
Я могу легко получить сообщение, но я не в состоянии получить «он» массив из ответа.
Вот моя модель данных класса
public class GetRoleData implements Serializable {
@SerializedName("he")
private ArrayList<Roles> he;
@SerializedName("message")
private String message;
public GetRoleData() {
this.he = new ArrayList<>();
this.message = "";
}
public ArrayList<Roles> getUserRoles() {
return he;
}
public String getMessage() {
return message;
}
public class Roles {
public Roles() {
name = "";
type = -1;
}
@SerializedName("name")
private String name;
@SerializedName("type")
private int type;
public int getType() {
return type;
}
public String getName() {
return name;
}
}
}
Это, как я посылаю запрос на сервер:
@POST("index.php/")
Call<GetRoleData> getUserRoles(@Body SetParams body);
вот как я посылаю запрос и обработки ответа
APIService apiService = retrofit.create(APIService.class);
Call<GetRoleData > apiCall = apiService.getUserRoles(params);
apiCall.enqueue(new Callback<GetRoleData >() {
@Override
public void onResponse(retrofit.Response<GetRoleData > mUserProfileData, Retrofit retrofit) {
Log.e("locale info", "mUserProfileData = " + mUserProfileData.body().toString());
if (pDialog != null) {
pDialog.dismiss();
}
if (mUserProfileData.body().getMessage().equals("success")) {
Log.e("locale info", "user roles = " + mUserProfileData.body().getUserRoles().size());
} else {
Toast.makeText(RegisterActivity.this, getResources().getString(R.string.get_role_error), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Throwable t) {
if (pDialog != null) {
pDialog.dismiss();
}
t.printStackTrace();
}
});
Что я хочу
Мне нужно получить массив «he» от ответа выше. Пожалуйста, помогите Спасибо.
здесь ответ, который я получаю ..
Пожалуйста, вставьте код, где вы делаете запрос и обработку ответа –
@vipinagrahari пожалуйста, проверьте. –
что «я не могу получить массив« он »от ответа« точно »? – Yazan