zoukankan      html  css  js  c++  java
  • Retrofit2.0+RxJava2.0问题


    问题1:java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 2 path $

    @FormUrlEncoded
    @POST("userLogin")
    Observable<Object> userLogin(@Field
    
    mPostLocation.userLogin(sfflag,telephone,
            password,phoneid,phonemodel,versions)
            .subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new BaseObserver<Object>(cnt) {

    @PartMap parameters can only be used with multipart encoding. (parameter #2)

    java.lang.IllegalArgumentException: Only one encoding annotation is allowed.
    @Field parameters can only be used with form encoding.

    @PartMap 需要使用注解/*@Multipart*/ 
    @Field需要使用到注解:@FormUrlEncoded

    两个不能同时使用,否则会报 Only one encoding annotation is allowed.

    使用@FieldMap Map<String,RequestBody> params,来代替@PartMap来存储多张图片,只使用@FormUrlEncoded,但是发现请求接口,老是提示request参数不正确。

     问题二:

    com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $

    Gson gson = new GsonBuilder()
            .setLenient()
            .create();
    
        Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("http://whatever.com")
            .addConverterFactory(GsonConverterFactory.create(gson))
            .build(); 
    

      https://stackoverflow.com/questions/27485346/malformedjsonexception-with-retrofit-api



    
    
  • 相关阅读:
    洛谷 P1080 [NOIP2012 提高组] 国王游戏
    洛谷 P4370 [Code+#4]组合数问题2
    洛谷 P4369 [Code+#4]组合数问题
    洛谷 P3311 [SDOI2014] 数数
    implicit关键字详解
    模式匹配
    option[T]、Any、Nothing、Null类型的介绍
    高阶函数
    函数的介绍
    集合
  • 原文地址:https://www.cnblogs.com/liyanli-mu640065/p/7277977.html
Copyright © 2011-2022 走看看