是否可以发布一个 json 对象包? [英] Is it possible to POST a package of json objects?

查看:87
本文介绍了是否可以发布一个 json 对象包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在构建一个应用程序,它必须发布一个带有一些信息的 json 数组以及带有将用于识别的用户凭据的 json 对象.是否可以使用用户凭据发布某种包含 json 对象数组 + 对象的包?我正在使用 Retrofit2.

so I am building an applications that has to POST a json array with some information and also json object with user credentials which are going to be used for identification. Is is possible to POST some kind of package that contains json object array + object with user credentials? I am using Retrofit2.

所以除了这个数组列表,我想通过一个 POST 请求发送凭据.

So beside this Array list I would like to send Credentials with one POST request.

public interface JsonPlaceHolderApi {

    @POST("hws/hibisWsTemplate/api/v1/order/posts/")
    Call<Post> createPost(@Body ArrayList<Post> post);
}

推荐答案

您必须创建一个凭据类,就像为数组创建一个类一样.然后,您创建另一个名为请求"的类,并将凭据和您的数组放入其中,如下所示:

You have to create a class for credentials just like you made a class for your array. Then you create another class named lets say "Request" and put credentials and your array in it like so:

public class Request {
    final ArrayList<Post> posts;
    final Credentials credentials;

    //constructor, getters/setters
    ...

然后在您的 api 中执行此操作:

and then in your api do this:

public interface JsonPlaceHolderApi {

    @POST("hws/hibisWsTemplate/api/v1/order/posts/")
   Call<Post> createPost(@Body Request post);
}

这篇关于是否可以发布一个 json 对象包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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