Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKangaroo Rewards
Courses Plus Student 5,699 PointsRetrofit 2 sending post json
I would like to send a json parameter with Retrofit 2. This is my json structure: { key1 = {allowInfo1=1, allowInfo2=1,allowInfo3=0 }, key2 = {allowInfo1=0, allowInfo2=0,allowInfo3=1 } }
I'm trying to do it using: @FormUrlEncoded @POST("/api/functionname") Call<Result> UpdateUserNotificationsSettings(@Field("infouser") String infouser, @FieldMap Map<String, Map<String, String>> settings);
but I'm not able to send it correctly.
Am I doing well using Map? Thanks in advance
1 Answer
Seth Kroger
56,413 PointsWith @FormUrlEncoded you're instructing Retrofit to use a different format than JSON. You should send a single object with a @Body annotation instead of @Field and Retrofit will serialize it as JSON for you. See the top two answers here: http://stackoverflow.com/questions/21398598/how-to-post-raw-whole-json-in-the-body-of-a-retrofit-request