如何从多个课程中返回c#

时间:2018-11-06 20:17:15

标签: c# rest

我不确定如何写标题,并已尽我所能进行搜索,但实际上仍不确定如何处理。

我需要创建一个看起来像这样的退货:

  

[   {   “ Name”:“ First | Last”,   “ Id”:1,   “允许”:true,   “ date”:“ datestring”,   “ EndTime”:“ 11:00 AM”,   “时间”:“ 10:00”   “设置”:[   {   “ id”:1   “ name”:“ TestName”,   “ maxValue”:100   }

我的代码,显然我不能在其中进行新设置,那么我该如何将该位推入返回值呢?还是我要彻底解决这个问题?

    public Information[] PMI(string Id)  
    {
        return new Information[]
        {
            new Information
            {
                Name = "First|Last",
                NameId = "1",
                Allowed = true,
                date = "Feb 1, 2018",
                EndTime = "1:00 PM",
                DateTime = "09:00"
            },
            new Settings
            {
                id = 1,
                name = "TestName",
                maxValue = "1000"
            }
        };
    }

public class Information
{
    public string Name { get; set; }
    public string Id { get; set; }
    public bool Allowed { get; set; }
    public string date { get; set; }
    public string EndTime { get; set; }
    public string DateTime { get; set; }

}

public class Settings
{
    public string id { get; set; }
    public string name { get; set; }
    public string maxValue { get; set; }
}

1 个答案:

答案 0 :(得分:0)

这将满足您的需求:

   public Information[] PMI(string Id)  
{
    return new Information[]
    {
        new Information
        {
            Name = "First|Last",
            NameId = "1",
            Allowed = true,
            date = "Feb 1, 2018",
            EndTime = "1:00 PM",
            DateTime = "09:00"
            Settings = new Settings
            {
                id = 1,
                name = "TestName",
                maxValue = "1000"
            }
        },

    };
}

public class Information
{
    public string Name { get; set; }
    public string Id { get; set; }
    public bool Allowed { get; set; }
    public string date { get; set; }
    public string EndTime { get; set; }
    public string DateTime { get; set; }
    public Settings Settings {get; set;}
}

public class Settings
{
    public string id { get; set; }
    public string name { get; set; }
    public string maxValue { get; set; }
}