Android中不完整的响应改进

时间:2015-07-09 13:58:07

标签: android json retrofit

我正在使用Retrofit进行网络通话。不幸的是,似乎我得到的数据不完整。

当我在浏览器中打开链接时,它会显示大的json数据。 http://test.holmusk.com/food/search?q=apple

但是,当我在我的Android应用程序中使用Retrofit时,它会在中间的某处停止,因为错误的状态为200错误,并且出现空错误。

以下是记录数据的最后一部分:

 "value": 119
    },
    "polyunsaturated": {
07-09 21:07:27.129  25661-25661/divinegrace.com.myapplication E/SearchFoodService﹕ 200 null

以下是我的代码:

public class SearchFoodService {

    IMyAppService mIMyAppService;

    private final String LOG_TAG = "SearchFoodService";

    public SearchFoodService(IMyAppService mIMyAppService) {
        this.mIMyAppService = mIMyAppService;
    }

    public void searchForFoodInformation(String foodName) {
        Callback<Void> callback = new Callback<Void>() {
            @Override
            public void success(Void s, Response response) {
                Log.d(LOG_TAG, response.toString());
            }

            @Override
            public void failure(RetrofitError error) {
                Log.e(LOG_TAG, "" + error.getResponse().getStatus() + " " + error.getBody());
            }
        };

        mIMyAppService.searchFood(foodName, callback);
    }
}



public interface IMyAppService {

    @GET(EndPoints.SEARCH_FOOD)
    void searchFood(@Query("q") String foodName,
                    Callback<Void> callback);


public class MyAppService {
    private IMyAppService mService;


    public MyAppService() { }

    public IMyAppService getMyAppService() {

        if (mService != null) {
            return mService;
        }

        RestAdapter restAdapter = new RestAdapter.Builder()
                .setEndpoint(Constants.TEST_URL)
                .build();

        restAdapter.setLogLevel(RestAdapter.LogLevel.FULL);

        mService = restAdapter.create(IMyAppService.class);

        return mService;
    }
}

0 个答案:

没有答案