使用Retrofit时出现 java.lang.IllegalArgumentException: URL query string "t={type}&p={page}&size={count}" ...

本文探讨了Retrofit在处理URL参数时遇到的问题,特别是关于使用@Path注解与URL中特殊字符的冲突,并提供了替代方案@Query注解来解决此问题。文章深入分析了相关错误提示和解决方案,帮助开发者避免常见错误。
/**
 * Created by leo on 16/4/30.
 */
public interface GanchaiService {
    @GET("digest?t={type}&p={page}&size={count}")
    Call<List<GanChaiEntry>> ListGanchaiEntry(@Path("type") int type
            , @Path("count") int count, @Path("page") int page);
}

这里报错

形如?t=1&p=2&size=3的url链接不能用@PATH注解

Query params have their own annotation which automatically appends to the URL.

使用@Query注解

    @GET("digest")
    Call<List<GanChaiEntry>> ListGanchaiEntry(@Query("t")int type
            , @Query("size") int count, @Query("p") int page);

参考:

http://stackoverflow.com/questions/24610243/retrofit-error-url-query-string-must-not-have-replace-block

转载于:https://www.cnblogs.com/krislight1105/p/5452202.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值