格式错误的JSON Retrofit2

时间:2016-11-10 05:47:12

标签: android json retrofit2

如何解决这个来自android模拟器的错误

error from android emulator

  

com.google.gson.stream.MalformedJsonException:使用JsonReader.setLenient(true)接受第1行第1行路径中格式错误的JSON $

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.

1 个答案:

答案 0 :(得分: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();