gpt4 book ai didi

java - 如何在 RETROFIT 中同时 POST ArrayList 和 String?

转载 作者:行者123 更新时间:2023-12-02 02:51:55 24 4
gpt4 key购买 nike

我正在尝试在 Retrofit 中发布 ArrayList 和字符串值。我怎样才能在同一个帖子中发送它们?我已经尝试过这个但没有成功。谢谢。

Eticet_post.java

@POST("/api/r_etiket")
Call<Result> post_etiket(@Body List< EtiketItem_List> items, @Body String FileNo);

Print_Screen.java

Retrofit retrofit = new Retrofit.Builder()
.baseUrl("myURL")
.addConverterFactory(GsonConverterFactory.create())
.build();
Etiket_Post etiket_post = retrofit.create(Etiket_Post.class);
String FileNo = FileId;
ArrayList<EtiketItem_List> items = new ArrayList<>();
for (int e = 0; e < okutulan_list.size(); e++) {
items.add(new EtiketItem_List(
okutulan_list.get(e).STOK_KODU,
okutulan_list.get(e).STOK_ADI,
okutulan_list.get(e).OlcuBrim,
okutulan_list.get(e).STHAR_GCMIK));
}
Call<Result> call = etiket_post.post_etiket(items, FileNo);
call.enqueue(new Callback<Result>() {
@Override
public void onResponse(Call<Result> call, Response<Result> response) {
Toast.makeText(Print_Screen.this, response.body().result, Toast.LENGTH_LONG).show();
}

@Override
public void onFailure(Call<Result> call, Throwable t) {
Toast.makeText(Print_Screen.this, t.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
});

最佳答案

You can send data in raw format using Retrofit2 like this.

    {
"String1" :"anyString",
"arrayList":[
{
"A":"Appple",
"B":"ball"
}
]

}

modelClass example

 @SerializedName("user_id")
@Expose
private String user_id;

@SerializedName("product")
@Expose
List<OneProductModel> oneProductModels;


public CartPost(String user_id, List<OneProductModel> oneProductModels) {
this.user_id = user_id;
this.oneProductModels = oneProductModels;
}

@POST("/api/r_etiket")
Call<Result> post_etiket(@Body modelClass);

关于java - 如何在 RETROFIT 中同时 POST ArrayList 和 String?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57102613/

24 4 0