Java 如何在android中使用改型获得Json响应中的数组数据?

Java 如何在android中使用改型获得Json响应中的数组数据?,java,android,retrofit,retrofit2,jsonresponse,Java,Android,Retrofit,Retrofit2,Jsonresponse,嘿,我得到了一个json响应,其中也包含字符串和数组,获取字符串可以很好地工作,但是当尝试获取数组类型的数据时,它在studio中出现了错误 { "body": [ { "customer": "erp touch", "description": [ "ythn", "bgtr", "ythn" ] } ] } 我能够找到客户,但无法进行描述,这是我用于描述的pojo @SerializedN

嘿,我得到了一个json响应,其中也包含字符串和数组,获取字符串可以很好地工作,但是当尝试获取数组类型的数据时,它在studio中出现了错误

{
"body": [
    {
       "customer": "erp touch",

      "description": [
        "ythn",
        "bgtr",
        "ythn"
    ]

  }
 ]
}
我能够找到客户,但无法进行描述,这是我用于描述的pojo

@SerializedName("description")
private List<String> description = null;

public List<String> getDescription() {
    return description;
}
将解决此问题,但数组中的元素可能会发生变化 所以实际上我不知道我应该使用多少文本视图,这才是真正的问题

有没有办法根据我的问题创建文本视图

任何建议或帮助都将不胜感激


再次感谢

setText不接受列表作为参数。您可以尝试使用加入列表中的项目。像这样加入

String result=TextUtils.join(“,”,orderListResponse.getDescription())

然后您可以调用
setText(result)


提示:确保先检查结果和描述

List<String> description = orderListResponse.getDescription();
if (description == null) { // show error }
List description=orderListResponse.getDescription();
如果(description==null){//show error}

尝试将append与文本视图一起使用

 for (String s : orderListResponse.getDescription()){
                description_tv.append(s);

当然,如果您试图将
List
设置为
文本视图
,则会出现错误,这需要一个
字符串
请尝试此操作,然后选中
description\u tv.setText(orderListResponse.getDescription().get(0))这将给我第一个元素我可以空检查结果变量,因为我是response.body()的描述这是我一直在寻找的答案,但请帮助我空的东西嘿,我编辑了我的问题,我面临着类似的问题,你可以去检查它吗>你不能只编辑一个提交与一个新问题。请在StackOverflow上写一篇新文章
List<String> description = orderListResponse.getDescription();
if (description == null) { // show error }
 for (String s : orderListResponse.getDescription()){
                description_tv.append(s);