当我运行它时,我的应用程序出现错误:
com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期为BEGIN_OBJECT但在第1行第1行路径为STRING
但我不知道如何解决它,即使我看到了一些解决此错误的解决方案,但不知道在哪里编辑或如何,你能帮助我吗?
这是我的改造部分机智服务器响应:
Gson gson = new GsonBuilder().setLenient().create();
OkHttpClient client = new OkHttpClient();
Retrofit retrofit = new Retrofit.Builder().baseUrl(Constants.BASE_URL).client(client).addConverterFactory(GsonConverterFactory.create(gson)).build();
final RequestInterface requestInterface = retrofit.create(RequestInterface.class);
User user = new User();
user.setEmail(ProfileFragment.Global.email);
final ServerRequest request = new ServerRequest();
request.setOperation("check");
request.setUser(user);
handler = new Handler();
runnable = new Runnable() {
public void run() {
Call<ServerResponse2> response1 = requestInterface.check( ProfileFragment.Global.email );
response1.enqueue( new Callback<ServerResponse2>() {
@Override
public void onResponse(Call<ServerResponse2> call, retrofit2.Response<ServerResponse2> response1) {
ServerResponse2 resp = response1.body();
Toast.makeText( BService.this, resp.getResult() , LENGTH_LONG ).show();
Toast.makeText( BService.this, ProfileFragment.Global.ID , LENGTH_LONG ).show();
Toast.makeText( BService.this, ProfileFragment.Global.Mylat , LENGTH_LONG ).show();
Toast.makeText( BService.this, ProfileFragment.Global.Mylong , LENGTH_LONG ).show();
if (resp.getResult().contains( "true" ))
{
Call<ServerResponse2> response2 = requestInterface.track( "123456" , ProfileFragment.Global.Mylong, ProfileFragment.Global.Mylong, "56" );
response2.enqueue( new Callback<ServerResponse2>() {
@Override
public void onResponse(Call<ServerResponse2> call, retrofit2.Response<ServerResponse2> response2) {
ServerResponse2 resp = response2.body();
我的界面:
@GET("project5/web/")
Call<ServerResponse2> check(@Query("email") String email );
@GET("project5/web/track/")
Call<ServerResponse2> track(@Query("id") String id,@Query("long") String longg, @Query("lat") String lat , @Query("battery") String battery);