gpt4 book ai didi

android - 是否可以 POST 一包 json 对象?

转载 作者:行者123 更新时间:2023-11-29 16:28:57 26 4
gpt4 key购买 nike

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

所以除了这个数组列表之外,我想用一个 POST 请求发送凭证。

public interface JsonPlaceHolderApi {

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

最佳答案

你必须做那样的事情

定义您的 API

public interface JsonPlaceHolderApi {

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

定义您的请求

public class PostRequest {
final ArrayList<Post> posts;
final String credentials; // or anything you want

PostRequest(ArrayList<Post> posts, String credentials) {
this.posts = posts;
this.credentials = credentials;
}
}

关于android - 是否可以 POST 一包 json 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57954204/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com