Android Retrofit POST ArrayList

后端 未结 2 975
执念已碎
执念已碎 2021-01-20 13:01

Trying to send List to server and have Bad Request Error.

public interface PostReviewApi {
        @FormUrlEncoded
        @POST(\         


        
2条回答
  •  梦谈多话
    2021-01-20 13:24

    Try using @Body annotation instead of @Field and passing a single ReviewBody object.

    class ReviewBody {
    
        public Review review;
    
        public ReviewBody(int placeId, float rating, String content, List tagList) {
            review = new Review(placeId, rating, content, tagList);
        }
    
        public class Review {
            @SerializedName("place_id")
            public int placeId;
            public float rating; 
            public String content;
            @SerializedName("tag_list")
            public List tagList;
    
            public Review(int placeId, float rating, String content, List tagList) {
                this.placeId = placeId;
                this.rating = rating;
                this.content = content;
                this.tagList = tagList;
            }
        }
    }
    

    @POST("/")
    void addReview(@Body ReviewBody body, Callback callback);
    

    (without @FormUrlEncoded)

提交回复
热议问题