如何使用多个节点和节点数组使用JSONCONVERT



目前,我可以通过数据集检索数据库值,并在C#中使用JSONCONVERT.Serialize((以基本的JSON格式将其放置在C中,但是我需要生成所有部分标题,分区,数组中的数组等。每个部分都是类的类和列表?但是,如何制作截面标题和标题" Mainsect"以及像不同客户端之类的值中的数组?

目前不使用牛顿。

我需要从数据库值生成这样的文件:

{
  "mainSection": [
    {
      "section1":
        [
          "curr_month"  : "February",
          "curr_year"   : "2018",
          "todays_date" : "02-02-2018",
          "dates" :
            [
                "29",
              "30",
              "31",
              "01",
              "02",
              "03",
              "04"
            ]
        ]
    },
    {
      "section2" :
        [
          "date_range_start" : "02-01-2018", //the range for kpi's is always from the 1st day of the month through yesterday
          "date_range_end" : "02-01-2018"
        ]
    },
    {
      "section3" :
        [
          "date_range_start" : "2-1-2018",
          "date_range_end" : "2-28-2018",
          "title" :
            {
              "count" : "225",
              "percentage" : "0"
            },
          "asecondtitle" :
            {
              "count" : "2645233",
              "percentage" : "9"
            },
          "athirdtitle" :
            {
              "count" : "437371",
              "percentage" : "7"
            }
        ]
    },
    {
      "section4" :
        [
          "title" : "Today'",
          "total_tile_count" : 4,
          "listofclients" :
            [
              {
                 "client_id" : "123456" 
                "type" : "walkin",
                "otherdata" : 13,
                "client_name" : "Client P0opyface",
                 "appointment_times":
                [
                    {
                        "scheduled_room" : "Room A", //sometimes they change operating rooms within the same day
                        "start_time" : "07:00",
                        "end_time" : "07:15"
                    },
                    {
                        "scheduled_room" : "Room B",
                        "start_time" : "07:15",
                        "end_time" : "07:30"
                    },
                    {
                        "scheduled_room" : "Room C",
                        "start_time" : "07:30",
                        "end_time" : "07:45"
                    }                   
                ]
              },
              {
                  "client_id" : "789" 
                "type" : "walkin",
                "otherdata" : 13,
                "client_name" : "Client Stinkyface",
                 "appointment_times":
                [
                    {
                        "scheduled_room" : "Room D", //sometimes they change operating rooms within the same day
                        "start_time" : "07:00",
                        "end_time" : "07:15"
                    },
                    {
                        "scheduled_room" : "Room E",
                        "start_time" : "07:15",
                        "end_time" : "07:30"
                    },
                    {
                        "scheduled_room" : "Room F",
                        "start_time" : "07:30",
                        "end_time" : "07:45"
                    },
{
                        "scheduled_room" : "Room G",
                        "start_time" : "08:30",
                        "end_time" : "08:45"
                    }                   
                ]
              },
              {
                "client_id" : "8675309" 
                "type" : "repeat",
                "otherdata" : 13,
                "client_name" : "Client Donkeybutt",
                 "appointment_times":
                [
                    {
                        "scheduled_room" : "Room H", //sometimes they change operating rooms within the same day
                        "start_time" : "07:00",
                        "end_time" : "07:15"
                    },
                    {
                        "scheduled_room" : "Room I",
                        "start_time" : "07:15",
                        "end_time" : "07:30"
                    }
                ]
              }
            ]
        ]
    }
  ]
}

我从未见过这种格式,也无法创建一种格式:

{
    "section1": [
        "curr_month" : "February",
        "curr_year" : "2018",
        "todays_date" : "02-02-2018"
    ]
}

所以,您是指这个:

{
    "section1": {
        "curr_month": "February",
        "curr_year": "2018",
        "todays_date": "02-02-2018"
    }
}

当属性" Section1"是用户定义的类或字典

或以下:

{
    "section1": [
        {
            "curr_month": "February",
            "curr_year": "2018",
            "todays_date": "02-02-2018"
        }
    ]
}

当属性" pection1"是用户定义类或字典的数组时

因此,如果这是偶然的错别字,我想说使用一个构造良好的班级是您的最佳选择,除非这种JSON格式正是您真正想要的。据我所知,在这种情况下,您可以使用字符串串联来构建格式。

最新更新