是否可以发布一个 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);
}