问题描述
我正在Android应用程序中使用okhttp Retrofit进行网络请求.在其中一个请求中,我收到此错误:
I am using okhttp Retrofit in my Android App to make network requests. On one of the requests I get this error:
com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期为BEGIN_OBJECT,但位于第1行第1列路径$
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
我在日志中看到201响应,但是Retrofit抛出此错误.下面是我的代码.
I see a 201 response in the logs but Retrofit throws this error. Below is my code.
signup(signupParams, new Callback<Member>() {
@Override
public void success(Member member, Response response) {
if (member != null) {
UserAccount userAccount = new UserAccount(member);
userAccount.save();
}
@Override
public void failure(RetrofitError re) {
BusProvider.post(new SignupFailedEvent(re, email));
}
});
signupParams值为-
signupParams value is --
{"emailAddress":"[email protected]","password":"tester123","userSource":"APH"}
我已经用jsonLint测试了这个json,它是有效的json.这是我的成员类,应该是理想的响应.
I have tested this json with jsonLint and it is a valid json. And this is my Member Class which should be the response ideally.
public class Member {
public String emailAddress;
public String token;
public long id;
public String firstName;
public String lastName;
}
响应示例应如下所示:
{
"emailAddress": "[email protected]",
"id": 1437811,
"token": "sdhshdghsdhhsdbcjhbsjdhc",
"firstName": "John",
"lastName": "Smith"
}
推荐答案
,如果您确定邮递员可以工作,并且模型与JSON参数相同,
if you sure the postman work, and the model same as the JSON parameter,
也许您使用了"accept-encoding:gzip"或像这样在您的请求标头中.
maybe you use the "accept-encoding: gzip" or like that in your request header.
retrofit不适用于gzip,请将其从标题中删除.
retrofit doesn't work with gzip, remove that from the header.
这篇关于Android Retrofit预期为BEGIN_OBJECT,但位于第1行第1列路径$ STRING的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!