java.io.EOFException:Android 改造中第 1 行第 1 列路径 $ 处的输入结束 [英] java.io.EOFException: End of input at line 1 column 1 path $ in Android retrofit

查看:86
本文介绍了java.io.EOFException:Android 改造中第 1 行第 1 列路径 $ 处的输入结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Retrofit 来使用 REST API 端点,但我遇到了以下问题.我认为 TransactionResponse 类上的数据模型有问题,但还不确定.

I'm using Retrofit to consume a REST API endpoint, and I'm having the following issue. I think the something is wrong with data model on TransactionResponse class, but not sure yet.

java.io.EOFException:第 1 行第 1 列路径 $ in 处的输入结束安卓改造

java.io.EOFException: End of input at line 1 column 1 path $ in Android retrofit

我的通话请求如下.

 @FormUrlEncoded
@POST("/ifapi.php")
Call<TransactionResponse> loadData(@Field("user") TransactionRequest user);

事务请求类:

import javax.annotation.Generated;

@Generated("org.jsonschema2pojo")

public class TransactionResponse {

    private Settings settings;
    /**
     *
     * @return
     * The settings
     */

    public Settings getSettings()
    {
        return settings;
    }
    /**
     *
     * @param settings
     * The settings
     */

    public void setSettings(Settings settings)
    {
        this.settings = settings;
    }

    private Actions actions;
    /**
     *
     * @return
     * The actions
     */
    public Actions getActions()
    {
        return actions;
    }
    /**
     *
     * @param actions
     * The actions
     */
    public void setActions(Actions actions)
    {
        this.actions = actions;
    }
}

下面是实际完成调用的代码.

And below is the code where call is actually done.

OkHttpClient httpClient = new OkHttpClient.Builder().build();
Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create()).baseUrl( 
RestAPI.BASE_URL).client(httpClient).build();
RestAPI service = retrofit.create(RestAPI.class);
Call<TransactionResponse> meResponse = service.loadData(request);

meResponse.enqueue(new Callback<TransactionResponse>() {
       @Override 
       public void onResponse(Call<TransactionResponse> call, Response<TransactionResponse> response) {
               if (response.isSuccessful()) {
                       TransactionResponse body = response.body();
                       Actions actions = body.getActions();
                       Map<String, String> params = actions.getParams();
               }
       }

       @Override
       public void onFailure(Call<TransactionResponse> call, Throwable t){
              t.printStackTrace();
       }
  });

谁能帮帮我?提前致谢.

Can anyone please help me? Thanks in advance.

我正在使用以下库.

compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'javax.annotation:javax.annotation-api:1.2'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'

P.S 我发现该请求适用于表单数据,但不适用于 JSON 数据.

P.S I found that the request worked with form data, but not with JSON data.

推荐答案

我已经找到了解决方案,你需要将每个参数以如下形式发布在表单中,而不是在包装类中.

I have found the solution, you need to post each parameters in the form as follows, not in a wrapper class.

@FormUrlEncoded

@POST("/ifapi.php")

Call<TransactionResponse> loadData(@Field("app_id") String app_id, @Field("install_id") String install_id, @Field("useragent") String useragent, @Field("ip") String ip, @Field("mccmnc") String mccmnc, @Field("action") String action );

对于主要活动部分.

OkHttpClient httpClient = new OkHttpClient.Builder().build();
Gson gson = new GsonBuilder()
                                       .setLenient()
                                       .create();
Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create(gson)).baseUrl(RestAPI.BASE_URL).client(httpClient).build();

RestAPI service = retrofit.create(RestAPI.class);
Call<TransactionResponse> meResponse = service.loadData("1", getUUID(), getUserAgent(), getIPAddress(), "20404", "start");

希望这能解决您的问题,问候.

Hope this will resolve your issues, Regards.

这篇关于java.io.EOFException:Android 改造中第 1 行第 1 列路径 $ 处的输入结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆