首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >畸形JSON Retrofit2

畸形JSON Retrofit2
EN

Stack Overflow用户
提问于 2016-11-10 05:47:12
回答 1查看 1.1K关注 0票数 0

如何解决我从from android仿真器获得的错误

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

代码语言:javascript
复制
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);
        }
    });
}

下面是应用的令牌=

代码语言:javascript
复制
"fQEG8hgG8oE:APA91bGKsH78Ft6wCDW2EtMsuC19EXl10pxkJ95ZrVwnmaofFcw8-TgxeASujQva_gM7gYijIduYL82TmR5qeExxaeHP_252ZOSx7in99ShnaKwE8bsnOyYBDAI4M34d3APCiJKpWDqC "

符号总数152个。

EN

回答 1

Stack Overflow用户

发布于 2016-11-10 05:58:11

'com.google.code.gson:gson:2.6.1'编译

代码语言:javascript
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40520719

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档