Таким образом, если вы не можете изменить ответ на "message": {},"message": {},"message": {}
, тогда синтаксический анализ JSONObject - единственный способ.
Первое создание:
public class Message {
@SerializedName("message_a")
private String message_a;
@SerializedName("message_b")
private String message_b;
public Message(String message_a, String message_b) {
this.message_a = message_a;
this.message_b = message_b;
}
public String getMessage_a() {
return message_a;
}
public void setMessage_a(String message_a) {
this.message_a = message_a;
}
public String getMessage_b() {
return message_b;
}
public void setMessage_b(String message_b) {
this.message_b = message_b;
}
}
}
public interface ApiInterface {
@GET("url")
Call<JSONObject> getCheck();
}
И, наконец, в вашей деятельности
private ApiInterface apiInterface;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
apiInterface = ApiClient.getApiClient().create(ApiInterface.class);
Call<JSONObject> call = apiInterface.getCheck();
call.enqueue(new Callback<JSONObject>() {
@Override
public void onResponse(Call<JSONObject> call, Response<JSONObject> response) {
try {
JSONObject suggestion = response.body().getJSONObject("suggestion");
Message message = new Message(suggestion.getJSONObject("message").getString("message_a"),
suggestion.getJSONObject("message").getString("message_b"));
Message message1 = new Message(suggestion.getJSONObject("message1").getString("message_a"),
suggestion.getJSONObject("message1").getString("message_b"));
Message message2 = new Message(suggestion.getJSONObject("message2").getString("message_a"),
suggestion.getJSONObject("message2").getString("message_b"));
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Call<JSONObject> call, Throwable t) {
}
});
}
Затем установите текст всего TextView
textView.setText(message.getMessage_a());
textView.setText(message.getMessage_b());