"java.lang.illegalStateExpection: Expected a string but was BEGIN_ARRAY at line 1 column 145 path $.docs[0].description"在科特林

"java.lang.illegalStateExpection: Expected a string but was BEGIN_ARRAY at line 1 column 145 path $.docs[0].description"in kotlin

主片段中有一个recycler视图,使用APIRetrofit调用items。 当我尝试构建时,API 调用了:onFailure。 然后错误:"java.lang.illegalStateExpection: Expected a string but was BEGIN_ARRAY at line 1 column 145 path $.docs[0].description" 我该如何解决这个问题?

API

interface API{
    @Headers("Authorization:token:String")

    @GET("/store/item/list")
    fun fetchAllList(@Header("Authorization") token: String?): Call<Result>
}

数据

data class Docs(
    val id: String,
    val title :String,
    val stock: String,
    val description: String
)

data class Result(
    val totalDocs: String,
    val currentPage: String,
    val pageSize: String,
    val totalPage: String,
    val docs: List<Docs>?
)

片段


class MainFragment: Fragment(), SwipeRefreshLayout.OnRefreshListener {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
    ): View? { return inflater!!.inflate(R.layout.fragmenta, container, false)}


    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

        val gson = GsonBuilder().create()
        val retrofit=Retrofit.Builder()
            .baseUrl("xxxx")
            .addConverterFactory(GsonConverterFactory.create(gson))
            .build()

        val api = retrofit.create(API::class.java)

        val token = SharedPreference.getTokenInfo(context!!)

        api.fetchAllList(token).enqueue(object : Callback<Result>{
            override fun onResponse(call: Call<Result>, response: Response<Result>) {
                showData(response.body()?.docs!!)
            Log.d("test", "complete")
        }
                override fun onFailure(call: Call<Result>, t: Throwable) {
            Log.d("test","error")
        } })
    }

    private fun showData(results: List<Docs>) {
        recycler_view.apply {
            recycler_view.layoutManager=androidx.recyclerview.widget.LinearLayoutManager(context)
            adapter=ItemRecyclerAdapter(results)
        }
    }

    override fun onRefresh() {
            swipeRefreshLo.isRefreshing = false

        }

    }

适配器

class ItemRecyclerAdapter(private val results: List<Docs>) : RecyclerView.Adapter<ItemRecyclerAdapter.ViewHolder>() {



    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
      val View = LayoutInflater.from(parent.context).inflate(R.layout.item_1_col_list,parent,false)

     return ViewHolder(View)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val result = results[position]
        holder.first.text=result.title

       }

    override fun getItemCount(): Int = results.size

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val first: TextView = itemView.titleText
    }
}


问题是 Docs.description 字段被声明为 String 但它在 JSON 响应中是一个数组。