使用Json主体为翻新呼叫捕获列表响应 [英] Capturing List response for a Retrofit Call with Json body

查看:80
本文介绍了使用Json主体为翻新呼叫捕获列表响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部.

我正在尝试使用Retrofit将原始JSON作为POST请求中的正文发送到服务器.

I am trying to use Retrofit to send raw json as a body in a POST Request to the server.

@POST("api/apps")
Call<List<GetApps>> getApp(@Body GetApps body);

我已经使用jsontopojo构建了模型,用于返回的响应.

I have built the model using jsontopojo for the responses that are coming back.

在我的调用中,我放置了构造函数,getter和setter以及toString().

Inside my call, I have put the constructors and the getters and setters and also toString().

这是我的改造电话.

        Retrofit retrofit = new Retrofit.Builder()
                        .baseUrl(APIUrl.BASEURL)
                        .addConverterFactory(GsonConverterFactory.create())
                        .build();

        APIService apiService = retrofit.create(APIService.class);

        Call<List<GetApps>> call = apiService.getApp();

        call.enqueue(new Callback<List<GetApps>>() {
            @Override
            public void onResponse(Call<List<GetApps>> call, Response<List<GetApps>> response) {
                List<GetApps> GetApps2 = response.body();


                Toast.makeText(getApplicationContext(),"success", Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onFailure(Call<List<GetApps>> call, Throwable t) {
                Toast.makeText(getApplicationContext(),"Failure", Toast.LENGTH_SHORT).show();


            }
        });

我在此行遇到错误:

Call<List<GetApps>> call = apiService.getApp();

它说getApp(getApps)不能应用于();不确定应在();中输入什么内容

It says getApp(getApps) cannot be applied to (); Not sure what should go into the ();

推荐答案

您必须传递GetApps对象作为参数:

You must pass GetApps object as parameter:

GetApps getApps = new GetApps();
//set all your data on getApps
//getApps.setYourData(yourData);
Call<List<GetApps>> call = apiService.getApp(getApps);

这篇关于使用Json主体为翻新呼叫捕获列表响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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