Hallo, ich benutze Retrofit für JSON Parsing.Ich habe 200 Antwort-Code, aber ich habe keine ordnungsgemäße Antwort auf meine ArrayList erhalten. Ich bekomme nur die Antwort auf "Status" Feld. Andere Felder werden null. Bitte Hilfe me.JSON Daten gegeben sind unten Danke :)Retrofit Antwort nicht erhalten
// json Parsing-Methode
private void load() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.build();
.addConverterFactory(GsonConverterFactory.create()).client(client)
Apiinterface request = retrofit.create(Apiinterface.class);
Call<MyPojo> call = request.newsget(new Newslist_Post("en",0));
call.enqueue(new Callback<MyPojo>() {
@Override
public void onResponse(Call<MyPojo> call, Response<MyPojo> response{
try {
if (response.code() == 200) {
Log.d("act", "onResponse - Status : " +response.code());
Gson gson = new Gson();
TypeAdapter<MyPojo>adapter=gson.getAdapter(MyPojo.class);
try {
if (response.errorBody() != null) {
Toast.makeText(MainActivity.this, "Request Success", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
MyPojo news_model = response.body();
// data = new ArrayList<>(Arrays.asList(news_model.getNews()));
status=news_model.isStatus();
count=news_model.getCount();
data=news_model.getNews();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Call<MyPojo> call, Throwable t) {
Toast.makeText(MainActivity.this, "Please Check your network",Toast.LENGTH_SHORT).show();
//Log.d("Error",t.getMessage());
}
});}
ModelClass
Diese Modellklassen die JSON, in diesem Modell Klassenliste zu analysieren verwendet erhalten zweite Modellklasse Inhalt
public class MyPojo{
@SerializedName("status")
private boolean status;
@SerializedName("count")
private int count;
@SerializedName("news")
private List<News>news;
public int getCount() {
return count;
}
public List<News> getNews() {
return news;
}
public boolean isStatus() {
return status;
}
zweite ModelClass
In dieser Modellklasse befinden sich News-Daten, diese News-Daten werden in die erste Modellklassenliste aufgenommen.
public class News
{
private String news_id;
private String newss_description;
private String newss_title;
private String news_image;
private String lang;
public String getNews_id()
{
return news_id;
}
public String getNewss_description()
{
return newss_description;
}
public String getNewss_title()
{
return newss_title;
}
public String getNews_image()
{
return news_image;
}
public String getLang()
{
return lang;
}
}
//JSON
{
"status": true,
"count": 2,
"news": [
{
"news_id": "2",
"news_image": "5fc2eaf170e6fc8ba6aa3974ce0c2e11.jpg",
"newss_title": "new 1",
"newss_description": "test news",
"lang": "en"
},
{
"news_id": "1",
"news_image": "31e3650272d006d24ac6c5fd580cace0.jpg",
"newss_title": "cooking class with tanya in the name of healthy",
"newss_description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
"lang": "en"
}
]
}
die Namen in der POJO @SerializedName das gleiche in Ihrem JSON-Antwort sein muss – Fakher