【问题标题】:How to post raw json below in the body of retrofit request?如何在改造请求正文中发布原始 json?
【发布时间】:2016-05-18 01:57:56
【问题描述】:

这里我使用的是改造 1.9,我必须在发布请求中发布这个 json。

{
"note": "",
"amount": "0",
"frequency": null,
"patient": "sameer_998oiib@innotical.com",
"doctor": "",
"date": "2016-04-27",
"reminder": 
[
{
    "days": [2],
    "time": "06:29:00"
}, 
{
    "days": [2, 3],
    "time": "06:30:00"
}
],
"salt": "Abobotulinum Toxin A Injection",
"method": 2,
"unit": 1
   } 

提前致谢。

【问题讨论】:

    标签: android json post retrofit


    【解决方案1】:

    只需创建一个类似的对象

    public class PostObject{
            String note;
            String amount;
            String frequency;
            String patient;
            String doctor;
            String date;
            String salt;
            int method;
            int unit;
            List<Reminder> reminder;
    
            class Reminder{
                List<Integer> days;
                String time;
            }
    
        }
    

    并设置您的请求正文对象

    【讨论】:

    • 使用您的值创建一个 PostObject,例如:PostObject object = new PostObject(....)
    • 我已经创建了这个类的对象,但我无法为日期和时间键赋值
    • 那我必须在 postObject 参数中传递提醒类对象?
    • 你可以这样设置:object.setReminder(reminder)
    猜你喜欢
    • 1970-01-01
    • 2014-02-19
    • 2020-06-18
    • 2019-12-11
    • 2021-03-04
    • 1970-01-01
    • 2017-06-17
    • 2019-06-06
    相关资源
    最近更新 更多