android - 如何在改造中使用原始 json 对象调用改造 @DELETE 方法?
问题描述
我尝试使用原始 json 对象删除 Retrofit 方法来删除我的列表项。我曾经将 POST 方法与 raw 方法一起使用,但我需要与 @DELETE 方法相同。这里发布方法代码:
@Headers("Content-Type:application/json")
@POST("api/tracking/post")
Call<MyResponse> getUser(@Body JsonObject jsonBody);
我需要这种类型的 DELETE 方法和带有这种类型 url 的原始对象
api/跟踪/删除/{user_id}
我试着用
@Headers("Content-Type:application/json")
@DELETE("api/tracking/delete/{user_id}")
Call<MyResponse> getUser(@Body JsonObject jsonBody);
我把我的json
{
"store_id":"oddeve78",
"user_id":1,
"api_token":"nzBxRT9lr2T0WDnd1DAA8Z6uXZRJQt3OyNkP6rfqCl8kEvNeyM7KoHvkqHU0}
解决方案
您可以创建一个函数来为您打包。如果你真的想传递 JsonObject。
public Call<MyResponse> getUserByUserId(JSONObject json) {
String userId = json.get("user_id");
if (userId == null) return null;
return getUser(userId);
}
你的电话:
@Headers("Content-Type:application/json")
@DELETE("api/tracking/delete/{user_id}")
Call<MyResponse> getUser(@Path("user_id) String userId);
推荐阅读
- python - Groupby 对列求和以获取每个项目的频率
- pandas - 从一个 DataFrame 绘制多条线
- python - 尝试在 python 中使用 (requests.post()) 发布时出现 500 内部服务器错误
- mysql - Mysql IF 语句在嵌套 if 语句上出错
- windows - Powershell + MegaCLI - 使输出更具可读性
- node.js - Nodejs、TypeScript、ts-node-dev 和顶级等待
- reactjs - 类型 'undefined' 不能分配给类型 'number | 大佬
- arrays - 无法使函数读取双数组
- winapi - 对函数的未定义引用,即使它应该是可访问的
- r - 在ggplot中为多个系列条形图有条件地着色条