Kotlin java.lang.IllegalStateException:使用GSON解析JSON时的JSON对象和JSON数组

Kotlin java.lang.IllegalStateException:使用GSON解析JSON时的JSON对象和JSON数组,kotlin,gson,retrofit2,Kotlin,Gson,Retrofit2,服务器JSON数据使用改型显示在活动中。JSON数据通过gson转换 给出错误:“java.lang.IllegalStateException:应为BEGIN_数组,但在第1行第2列路径$处为BEGIN_对象” JSON格式: {"success":1,"company":[{"Cmp_Id":"1","Cmp_Name":"ABC","GSTIN":"AAAA"}]} 代码: 改装界面: interface APIInterface { @GET("Company.php") fu

服务器JSON数据使用改型显示在活动中。JSON数据通过gson转换

给出错误:“java.lang.IllegalStateException:应为BEGIN_数组,但在第1行第2列路径$处为BEGIN_对象”

JSON格式:

{"success":1,"company":[{"Cmp_Id":"1","Cmp_Name":"ABC","GSTIN":"AAAA"}]}
代码:


改装界面:

interface APIInterface {
  @GET("Company.php")
  fun getCompanyData() : Observable<List<CompanyList>>
}
将提示您需要一个类型为
CompanyList
的单一对象,这应该适用于您发布的json

private fun fetchData(){
   /* compositeDisposable.add(api.getCompanyData()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe { companyList-> displayData(companyList)
            }
    )*/

    val retrofit = APIClient.apIClient
    if (retrofit != null) {
        api = retrofit.create(APIInterface::class.java)
    }

    api.getCompanyData()
            .subscribeOn(Schedulers.io())
            .unsubscribeOn(Schedulers.computation())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({ companyAdapter.setCompany(it.component1().company)
            },{

                Toast.makeText(applicationContext, it.message, Toast.LENGTH_SHORT).show()


            })
}
interface APIInterface {
  @GET("Company.php")
  fun getCompanyData() : Observable<List<CompanyList>>
}
interface APIInterface {
  @GET("Company.php")
  fun getCompanyData() : Observable<CompanyList>
}