改造:java.lang.IllegalStateException:预期为BEGIN_OBJECT,但在第1行第1列路径$ STRING

时间:2019-12-24 04:00:48

标签: android kotlin retrofit2

我使用Retrofit 2向Webservice API发出请求。

我创建了一个用于解析它的类:

data class OrderList(
    @SerializedName("current_page") @Expose val current_page: String?,
    @SerializedName("first_page_url") @Expose val first_page_url: String?,
    @SerializedName("from") @Expose val from: String?,
    @SerializedName("last_page") @Expose val last_page: String?,
    @SerializedName("last_page_url") @Expose val last_page_url: String?,
    @SerializedName("next_page_url") @Expose val next_page_url: String?,
    @SerializedName("per_page") @Expose val per_page: String?,
    @SerializedName("prev_page_url") @Expose val prev_page_url: String?,
    @SerializedName("to") @Expose val to: String?,
    @SerializedName("total") @Expose val total: String?,
    @SerializedName("list") @Expose val list:List<Order>? 
)

data class OrderList( @SerializedName("current_page") @Expose val current_page: String?, @SerializedName("first_page_url") @Expose val first_page_url: String?, @SerializedName("from") @Expose val from: String?, @SerializedName("last_page") @Expose val last_page: String?, @SerializedName("last_page_url") @Expose val last_page_url: String?, @SerializedName("next_page_url") @Expose val next_page_url: String?, @SerializedName("per_page") @Expose val per_page: String?, @SerializedName("prev_page_url") @Expose val prev_page_url: String?, @SerializedName("to") @Expose val to: String?, @SerializedName("total") @Expose val total: String?, @SerializedName("list") @Expose val list:List<Order>? )

我的生成器请求


    val okHttpClient = OkHttpClient.Builder()
            .addInterceptor { chain ->
                val original = chain.request()
                var requestBuilder = original.newBuilder()
                val request = requestBuilder.build()
                chain.proceed(request)
            }.build()
        var gson = GsonBuilder()
            .setLenient()
            .create()

        val instance: Api by lazy {
            val retrofit = Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(NullOnEmptyConverterFactory)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .client(okHttpClient)
                .build()
            retrofit.create(Api::class.java)
        }

改造界面:



    @Multipart
        @Headers("Content-Type:application/json")
        @POST("api/v1/shipper/shippings")
        fun orderList(
            @Header("Authorization") token:RequestBody,
            @Part("status") email: RequestBody?,
            @Part("page") name: RequestBody?
        ): Call

Json Postman


    {"current_page":1,"first_page_url":"https://ishipee.teamtn.net/api/v1/shipper/shippings?page=1","from":1,"last_page":1,"last_page_url":"https://ishipee.teamtn.net/api/v1/shipper/shippings?page=1","next_page_url":null,"per_page":50,"prev_page_url":null,"to":4,"total":4,"list":[{"order_number":1,"type_ship":"NORMAL","status":0,"note":null,"amount":0,"currency_symbol":"PHP","currency_symbol_position":"right","currency_thousad_sep":",","currency_decimal_sep":".","currency_decimal_number":2,"pickup_info":{"name":"Nguyen Van A","phone":"09877225485","address":"Unit 1106 Abra - Bangued - Agtangao"},"destination_info":{"name":"Nguyen Van B","phone":"09877225487","address":"Unit 2721 Agusan Del Norte - Buenavista - Macalang"},"package":{"type":"weight","value":"1"}}]}

我负责的是成功,但解析时却有问题。有经验:

java.lang.IllegalStateException:预期为BEGIN_OBJECT,但在第1行第1列路径$

请大家,我需要您的帮助! 谢谢

0 个答案:

没有答案