我收到以下错误:
com.google.gson.JsonSyntaxException:java.lang.IllegalStateException: 期望一个字符串,但在第1行第2列路径$
处是BEGIN_OBJECT
我正在使用以下代码:
在应用类中:
public static void setupRetrofit() {
OkHttpClient client = new OkHttpClient();
client.interceptors().add(new NewRequestIntercepter(mContext));
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
service = retrofit.create(ApiService.class);
}
public static ApiService getApiService() {
return service;
}
}
接口类
public interface ApiService
{
@POST("users")
Call<String> registerUser(@Body JsonObject jsonObject);
}
登录活动类
JsonObject Obj = new JsonObject();
JsonObject userObj = new JsonObject();
Obj.addProperty("email", "mark@gmail.com");
Obj.addProperty("name", "Mark"));
Obj.addProperty("gender", "Male");
userObj.addProperty("userInfo",obj);
Call<String> registerUserAPI = SoulCurry.getApiService().registerUser(userObj);
registerUserAPI.enqueue(new Callback<String>() {
@Override
public void onResponse(retrofit.Response<String> response, Retrofit retrofit) {
if (response.isSuccess())
CurryLogger.d("LoginActivity", response.toString());
}
@Override
public void onFailure(Throwable t) {
CurryLogger.d("Fail");
}
});
} catch (Exception e) {
e.printStackTrace();
}
}