且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

改造 2 错误:java.lang.IllegalStateException:预期为 BEGIN_OBJECT 但在第 6 行第 1 列路径为 STRING

更新时间:2023-02-18 17:21:13

我认为问题不在于您的代码,只需检查您的服务器日志,您的服务器发送给您的 json 字符串与您当前的匹配预期输出 json

I think problem is not in your code just check your server log, what json string your server send to you match with your current expected output json

要检查服务器输出,您可以使用 postman 或 restclient - 只需传递您的 url、方法和参数

To check server output you can use postman or restclient - just pass your url ,method ,and parameter

其次,建议您使用可序列化的 pojo 类,例如

secondly ill suggest you to user serializable pojo class like

public class UserList implements Serializable {

}
public class UserDatum implements Serializable {

}

发送到服务器的对象必须实现Serializable或parcelable接口

我使用过这样的东西 GsonConverterFactory.create()

Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(ROOT)
                .client(defaultHttpClient)
                .addConverterFactory(GsonConverterFactory.create())
                .build();