5
@GET
Call<List<User>> getMyFriends(@Header(GlobalDeclarationsRetrofit.HEADER_AUTHORIZATION) String lang, @Url String url, "Need to send a json object here");

任何帮助都应不胜感激..

4

1 回答 1

7

您可以将参数作为 hashmap 或 pojo 发送,参数将作为 JSON 对象发送。作为:

@POST("user/checkloc")
Call<CheckLocation> checkLocation(@Body Location location);

这里的位置是 pojo 对象:

public class Location {
String lat,lng;

    public Location(String lat, String lng) {
        this.lat = lat;
        this.lng = lng;
    }
}

它会将参数作为 JSON 对象发送为:

D/OkHttp﹕ --> POST /api/index.php/user/checkloc HTTP/1.1
D/OkHttp﹕    {"lat":"28.4792293","lng":"77.043042"}

您还可以将参数作为 Hashmap 发送:

@POST("user/checkloc")
Call<CheckLocation> checkLocation(@Body HashMap<String, String> hashMap);
于 2016-01-02T12:22:55.607 回答