【发布时间】:2018-07-12 19:19:02
【问题描述】:
我不知道如何使用改造来解析 json。熟悉使用 Retrofit 解析简单的 json,但不熟悉使用 Retrofit 解析 nested Json。
这是我的 Json 数据......
{
"current_observation": {
"image": {
"url":"http://icons.wxug.com/graphics/wu2/logo_130x80.png",
"title":"Weather Underground",
"link":"http://www.wunderground.com"
},
{
"url":"http://icons.wxug.com/graphics/wu2/logo_130x80.png",
"title":"Weather Underground",
"link":"http://www.wunderground.com"
}
}
}
}
任何帮助将不胜感激。 谢谢。
这是我的简单 json 方法
public class Country {
@SerializedName("current_observation")
@Expose
private List<Items> items;
public List<Items> getItems() {
return items;
}
public void setItems (List<Items> items) {
this.items = items;
}
}
来了.....
public class Items {
@SerializedName("image")
@Expose
private String url;
private String title;
private String link;
public String getFlag() {
return url;
}
public String getRank() {
return link;
}
public void setRank(String link) {
this.link = link;
}
public void setFlag(String url) {
this.url = url;
}
public String getCountryname() {
return title;
}
public void setCountryname(String rating) {
this.title = rating;
}
}
主活动中的代码
Call <Country> call = apiInterface.getCountries();
call.enqueue(new Callback <Country>() {
@Override
public void onResponse(Call<Country> call, Response<Country> response) {
Log.d(TAG,"onSuccess Server Response "+ response.toString());
Log.d(TAG,"onSuccess received information "+ response.body().toString());
List<Items> items = response.body().getItems();
adapter = new RecAdapter(items, getContext().getApplicationContext());
recyclerView.setAdapter(adapter);
}
【问题讨论】:
-
不需要解析JSON对象,在模型类中使用注解
-
向我们展示您如何处理您的“简单 json”,然后我们将建议如何修改
-
是的,我会展示它。 @Jacky
-
@farhana 是的,我知道。我的简单 json 代码将显示更多亮点
-
@Jacky 请通过我的代码
标签: android arrays json retrofit