2016-11-10 77 views
0

如何解決這個錯誤我從一開始從Android模擬器畸形的JSON Retrofit2

error from android emulator

com.google.gson.stream.MalformedJsonException:使用JsonReader.setLenient(真)接受畸形的JSON位於第1行第1條路徑$

private void registerToken(final String token) { 

    Retrofit retrofit = new Retrofit.Builder() 
      .baseUrl(Constants.BASE_URL) 
      .addConverterFactory(GsonConverterFactory.create()) 
      .build(); 

    tokenPostAPI = retrofit.create(TokenPostAPI.class); 
    Call<String> tokenPostCall = tokenPostAPI.request(token); 

    studentPostCall.enqueue(new Callback<String>() { 
     @Override 
     public void onResponse(Call<String> call, Response<String> response) { 
     } 
     @Override 
     public void onFailure(Call<String> call, Throwable t) { 
      Log.e("token", "onFailure: "+t.toString()); 
      Log.e("token", "onFailure: applied token "+token); 
     } 
    }); 
} 

這裏是施加標記=

"fQEG8hgG8oE:APA91bGKsH78Ft6wCDW2EtMsuC19EXl10pxkJ95ZrVwnmaofFcw8-TgxeASujQva_gM7gYijIduYL82TmR5qeExxaeHP_252ZOSx7in99ShnaKwE8bsnOyYBDAI4M34d3APCiJKpWDqC " 

總代用字符152

+0

的錯誤意味着你嘗試解析不正確JSON。看看http://www.json.org/的正確語法 – Henry

回答

0

編譯 'com.google.code.gson:GSON:2.6.1'

Gson gson = new GsonBuilder() 
     .setLenient() //building as lenient mode`enter code here` 
     .create(); 

Retrofit retrofit = new Retrofit.Builder() 
     .baseUrl(BASE_URL) 
     .addConverterFactory(GsonConverterFactory.create(gson)) 
     .build(); 
+0

在您的問題部分添加這個 –

+0

謝謝IntelliJ Amiya –