草庐IT

java - JSON 错误 "java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $"

coder 2023-11-28 原文

public interface UserService {
    @POST(Constants.Api.URL_REGISTRATION)
    @FormUrlEncoded
    BaseWrapper registerUser(@Field("first_name") String firstname, @Field("last_name") String lastname, @Field("regNumber") String phone, @Field("regRole") int role);


 public BaseWrapper registerUser(User user) {
        return getUserService().registerUser(user.getFirstName(), user.getLastName(), user.getPhone(), user.getRole());
    }

这会产生异常

 com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

非常感谢您的帮助。

最佳答案

让我们看看您收到的错误。

Expected BEGIN_OBJECT

您的 JSON 是一个对象,所有 JSON 对象都包含在大括号 ({}) 中。因此 BEGIN_OBJECT 是 {.它在某处期待它。

but was STRING

但他却发现了一个字符串“Something”。仍然没有告诉我们在哪里。

at line 1 column 1 path $

啊,完美。在第 1 行第 1 列。这是 JSON 的开头。所以您忘记了将整个内容包含在 {} 中(或者至少您忘记了第一个,但我敢打赌您两个都忘记了)。

关于java - JSON 错误 "java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31424372/

有关java - JSON 错误 "java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $"的更多相关文章

随机推荐