java.lang.IllegalStateException:预期 BEGIN_ARRAY 但在第 1 行第 13 列路径 $.profile BEGIN_OBJECT
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 13 path $.profile
这就是我在这里编写代码的方式。这里有13个数据classes。我该如何处理这些?我该如何解决这个错误?
我的数据class:
//
data class ProfileResponse(
val call_permit: CallPermit,
val educations: List<Education>,
val languages: List<Language>,
val profile: List<Profile>,
val skills: List<Skill>,
val trainings: List<Training>,
val work_experience: List<WorkExperience>
)
我的 apiServiceClass:
@GET("call/profile/{postNumber}")
suspend fun getProfileShow(
@Path("postNumber") number:String
):Response<ProfileResponse>
存储库:
suspend fun getProfileShow(number: String): Response<ProfileResponse> {
return apiService.getProfileShow(number)
}
视图模型class:
val
response:MutableLiveData<Response<ProfileResponse>>=MutableLiveData()
fun getProfileShow(number : String) =viewModelScope.launch{
val res = repository.getProfileShow(number)
response.value=res
}
主要class:
viewModel.getProfileShow(ques.user_id)
viewModel.response.observe(viewLifecycleOwner, Observer { response ->
if(response.isSuccessful){
binding.profileSurename.text=response.body()?.toString()
}else {
Toast.makeText(requireContext(), response.code(), Toast.LENGTH_SHORT).show()
}
})
您从响应中获得对象列表。但是你只能得到对象。那是你得到一个错误。您必须在对象的响应配置文件中声明。
这就是我在这里编写代码的方式。这里有13个数据classes。我该如何处理这些?我该如何解决这个错误?
我的数据class: //
data class ProfileResponse(
val call_permit: CallPermit,
val educations: List<Education>,
val languages: List<Language>,
val profile: List<Profile>,
val skills: List<Skill>,
val trainings: List<Training>,
val work_experience: List<WorkExperience>
)
我的 apiServiceClass:
@GET("call/profile/{postNumber}")
suspend fun getProfileShow(
@Path("postNumber") number:String
):Response<ProfileResponse>
存储库:
suspend fun getProfileShow(number: String): Response<ProfileResponse> {
return apiService.getProfileShow(number)
}
视图模型class:
val
response:MutableLiveData<Response<ProfileResponse>>=MutableLiveData()
fun getProfileShow(number : String) =viewModelScope.launch{
val res = repository.getProfileShow(number)
response.value=res
}
主要class:
viewModel.getProfileShow(ques.user_id)
viewModel.response.observe(viewLifecycleOwner, Observer { response ->
if(response.isSuccessful){
binding.profileSurename.text=response.body()?.toString()
}else {
Toast.makeText(requireContext(), response.code(), Toast.LENGTH_SHORT).show()
}
})
您从响应中获得对象列表。但是你只能得到对象。那是你得到一个错误。您必须在对象的响应配置文件中声明。