Android 如何解决此错误:应为BEGIN_数组,但在第1行第2列路径处为BEGIN_对象$

Android 如何解决此错误:应为BEGIN_数组,但在第1行第2列路径处为BEGIN_对象$,android,kotlin,retrofit,multipart,Android,Kotlin,Retrofit,Multipart,我怎样才能解决这个问题? 我不知道解决方法。 检查我的代码并帮助我plz 请忽略:看起来你的帖子大部分是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分

我怎样才能解决这个问题? 我不知道解决方法。 检查我的代码并帮助我plz

请忽略:看起来你的帖子大部分是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息。看起来你的帖子大部分都是代码;请添加更多详细信息

class InformationActivity : AppCompatActivity() {
    private val _tag = SplashActivity::class.java.simpleName

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_information)


        val uniqueId = SharedPreference.getidInfo(this)

        val token = SharedPreference.getUserInfo(this)


        Client.retrofitService.profile(uniqueId, token)
            .enqueue(object : Callback<LoginResponse> {
                override fun onFailure(call: Call<LoginResponse>, t: Throwable) {

                }

                override fun onResponse(
                    call: Call<LoginResponse>,
                    response: Response<LoginResponse>
                ) {
                    if (response?.isSuccessful == false) { val er = Gson().fromJson(response.errorBody()?.charStream(), ErrorResponse::class.java)
                        Log.d(_tag, "${er.code}:${er.message}")
                        if (er.code == 60203) {
                            Toast.makeText(this@InformationActivity, "", Toast.LENGTH_SHORT).show()
                        }
                    } else if (response?.isSuccessful == true) {
                        Glide.with(applicationContext).asBitmap().load("https://s3.amazonaws.com/appsdeveloperblog/micky.gif").into(imageView)
                        Toast.makeText(this@InformationActivity, "", Toast.LENGTH_LONG).show()

                        val file=File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),"micky.gif")
                        var fileName="micky.gif"

                        val token = SharedPreference.getUserInfo(applicationContext)
                        val uniqueId= SharedPreference.getidInfo(applicationContext)

                        var requestBody: RequestBody = RequestBody.create(MediaType.parse("image/*"), file)
                        val body: MultipartBody.Part = MultipartBody.Part.createFormData("profile",fileName,requestBody)

                            if (uniqueId != null) {
                                Client.retrofitService.updateProfile(token,uniqueId,body)
                                    .enqueue(object : Callback<List<LoginResponse>> {
                                        override fun onFailure(
                                            call: Call<List<LoginResponse>>,
                                            t: Throwable) { Log.d("", t.message) }

                                        override fun onResponse(
                                            call: Call<List<LoginResponse>>,
                                            response: Response<List<LoginResponse>>) { if (response?.isSuccessful)
                                        { Toast.makeText(this@InformationActivity, "File Uploaded Successfully...", Toast.LENGTH_LONG).show()
                                                Log.d("", "" + response?.body().toString())
                                            } else {
                                                Toast.makeText(this@InformationActivity, "Some error occurred...", Toast.LENGTH_LONG).show()
                                            }
                                        } }) }
                        }
                    }
            }) }
}


您的json返回为json对象。但您正在尝试转换为Json数组

 Call<List<Loginresponse>> - you try to convert result as JSON Array (list) 
Call-您尝试将结果转换为JSON数组(列表)
解决方案


获取原始json结果并使用转换pojo,然后重试

您的json返回为json对象。但您正在尝试转换为Json数组

 Call<List<Loginresponse>> - you try to convert result as JSON Array (list) 
Call-您尝试将结果转换为JSON数组(列表)
解决方案


获取原始json结果并使用转换pojo,然后重试

您试图将json对象存储在列表中,这就是为什么会出现错误。 检查JSON响应以{花括号开始,这意味着它是对象而不是数组。数组以[方括号]开始

@PUT("/user/profile/{userId}")
fun updateProfile(@Header("Authorization") token: String?, @Path("userId") userID: String, @Part file: MultipartBody.Part): Call<List<Loginresponse>>
@PUT(“/user/profile/{userId}”)
fun updateProfile(@Header(“Authorization”)token:String?,@Path(“userId”)userId:String,@Part file:MultipartBody.Part):调用

使用
updateProfile
方法将
Call
替换为
Call
,您试图在列表中存储json对象,这就是您出错的原因。 检查JSON响应以{花括号开始,这意味着它是对象而不是数组。数组以[方括号]开始

@PUT("/user/profile/{userId}")
fun updateProfile(@Header("Authorization") token: String?, @Path("userId") userID: String, @Part file: MultipartBody.Part): Call<List<Loginresponse>>
@PUT(“/user/profile/{userId}”)
fun updateProfile(@Header(“Authorization”)token:String?,@Path(“userId”)userId:String,@Part file:MultipartBody.Part):调用

使用
updateProfile
方法将
Call
替换为
Call
,显示json响应此错误明确表示您希望应用程序上有一个数组,当api调用返回对象响应时,尝试转换
显示json响应的所有引用此错误明确表示当api调用返回对象响应时,请尝试转换

@PUT("/user/profile/{userId}")
fun updateProfile(@Header("Authorization") token: String?, @Path("userId") userID: String, @Part file: MultipartBody.Part): Call<List<Loginresponse>>