如何正确回调新闻源JSON传递单个API category_name

z9ju0rcb  于 2023-08-08  发布在  Go
关注(0)|答案(1)|浏览(87)

如何在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;

}

n9vozmp4

n9vozmp41#

根据java的命名约定规则,Class名称应该始终以大写字母开头。
因为newsfeed是一个java类,所以应该将其重命名为NewsFeed
Read more about Java Naming Conventions
由于您在API响应中接收到newsfeed数组,因此还需要在CallbackHome类中重构newsfeed变量声明,如下所示

public ArrayList<NewsFeed> newsfeed = new ArrayList<>();

字符串

相关问题