【问题标题】:Unable to use retrofit2 convertor无法使用改造 2 转换器
【发布时间】:2020-05-17 01:32:58
【问题描述】:

所以我正在尝试使用改造 GsonConvertorFactory 但在 android studio 中,它没有读取,因此我无法运行。

    public class start {

            private  static final String id = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
            private  static final String url = "https://XXX/YY/ZZ";

            public static PostService postService = null;
            public static PostService getService()

            {
                if (postService == null) {
                    Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConvertorFactory.create()).build();
                    postService = retrofit.create((PostService.class));
                }
                return postService;
            }


        public interface PostService{
            @GET("?=id"+id )
            Call<PostDia> getPostDia();
        }
    }

【问题讨论】:

  • 您的实际问题是什么?你没有说清楚。显示Error 消息或日志。用更多上下文描述您的问题,以便任何人都能理解。

标签: java android gson


【解决方案1】:

你需要添加:

    implementation 'com.squareup.retrofit2:converter-gson:2.8.1'

到 build.gradle 文件

【讨论】:

    【解决方案2】:

    我发现 GsonConvertorFactory 仅受 2.3.0 版本支持,不支持任何其他版本,因此请尝试更改您的依赖项

    实现 'com.squareup.retrofit2:converter-gson:2.3.0' 实现 'com.squareup.retrofit2:retrofit:2.3.0'

    【讨论】:

      猜你喜欢
      • 2016-06-23
      • 2015-12-30
      • 2021-05-13
      • 2018-10-19
      • 1970-01-01
      • 2019-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多