gpt4 book ai didi

android - 如何在android中的Retrofit 2的 'Body'参数中传递字符串

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:31:24 28 4
gpt4 key购买 nike

@POST("api/login")
Call<ApiResponse> loginUser(@Body String user);

这里的字符串实际上是一个 JSONstring 即

{"email":"test@gmail.com","password":"test"}

无法弄清楚这里有什么问题。它再次将字符串转换为 json。请建议..

这就是我想要对我的请求执行的操作,如图所示。

enter image description here

最佳答案

在对象中转换你的数据

public class Credentials
{
public String email;
public String password;
}

将数据设置为对象

Credentials loginCredentials = new Credentials();
loginCredentials.email = "test@gmail.com";
loginCredentials.password = "password";

调用你的 api

@POST("api/login")
Call<ApiResponse> loginUser(@Body Credentials credentials);

关于android - 如何在android中的Retrofit 2的 'Body'参数中传递字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35082844/

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