如何在翻新中使用原始json对象调用Retrofit @DELETE方法?

时间:2019-10-02 06:27:38

标签: android json http retrofit retrofit2

我尝试使用原始json对象删除Retrofit的方法来删除我的列表项。我曾经将POST方法与未成功完成的raw方法一起使用,但我需要与@DELETE方法相同。在这里发布方法代码:

(cd /test/path/ ; ls -d */ | awk -F'/' '{print $(NF-1)}' | sort -nr) 

我需要这种带有原始类型的url的DELETE方法

  

api / tracking / delete / {user_id}

我尝试

@Headers("Content-Type:application/json")
@POST("api/tracking/post")
Call<MyResponse> getUser(@Body JsonObject jsonBody);

我放了json

@Headers("Content-Type:application/json")
@DELETE("api/tracking/delete/{user_id}")
Call<MyResponse> getUser(@Body JsonObject jsonBody);

1 个答案:

答案 0 :(得分:0)

您可以创建一个函数来为您打包。如果您真的想传递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);