如何在JSON中传递newsfeed category_name
回调。public newsfeed newsfeed = null;
应用程序在写入时崩溃。
JSON API:
object {8}
status :ok
featured [1]
category [5]
menu [5]
shopmenu
newsfeed [1]
cid :28
category_name :mobile
recipes_count :5
字符串
此回调数据
public class CallbackHome implements Serializable {
public String status = "";
public List<Recipe> featured = new ArrayList<>();
public List<Category> category = new ArrayList<>();
public List<menu> menu = new ArrayList<>();
public List<shopmenu> shopmenu = new ArrayList<>();
public newsfeed newsfeed = null;
public List<Recipe> recent = new ArrayList<>();
public List<Recipe> videos = new ArrayList<>();
}
型
如何正确回调新闻源数据category_name
如何传递新闻源类别名称单数据。
displayData2(responseHome.newsfeed);
category_name = root_view.findViewById(R.id.mywidget);
public void displayData2(final newsfeed newsfeed) {
category_name.setText(newsfeed.category_name);
}
型
模型类
public class newsfeed implements Serializable {
public int cid = -1;
public String category_name;
}
型
1条答案
按热度按时间n9vozmp41#
根据java的命名约定规则,
Class
名称应该始终以大写字母开头。因为
newsfeed
是一个java类,所以应该将其重命名为NewsFeed
。Read more about Java Naming Conventions
由于您在API响应中接收到
newsfeed
数组,因此还需要在CallbackHome
类中重构newsfeed变量声明,如下所示字符串