android retrofit ,post whole Pojo using this format

孤人 提交于 2019-12-20 06:39:55

问题


I want to post this kind of request in retrofit2 so if someone have idea about it then it would be great help of mine.

reqObject={"task":"singleUser","taskData":{"userID":"1"}}

回答1:


Yes, good Question It is some what not understandable for Beginner.

So I combining some Answers for you.

first step

make your Json -> model class (or POJO class)

  1. From GsonFormattor plugin

This plug-in convert your Json to Model class

  1. Pojo genrator

Go to this link , copy and paste Your Json and simply make your model class.

OK , we completed our first step

Second Step

Set all value to your Model class what You want from getter() setter().

Retrofit having @Body annotation that use in your case

@POST("/jayson")
FooResponse postJson(@Body MyGsonModelClass body);

Where MyGsonModelClass is class we made from first step.



来源:https://stackoverflow.com/questions/42949839/android-retrofit-post-whole-pojo-using-this-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!