簡體   English   中英

如何將 Jsonconvert 與多個節點和節點數組一起使用

[英]how to use Jsonconvert with multiple nodes and arrays of nodes

目前,我可以通過數據集檢索數據庫值,並使用 c# 中的 JSONCOnvert.serialize() 將它們放入基本的 JSON 格式,但我需要生成所有部分標題、分區、數組中的數組等。每個部分都會是一個班級和班級列表? 但是我如何制作部分標題和標題“mainSection”,以及像不同客戶端一樣的值中的數組?

目前不使用牛頓。

我需要從數據庫值生成這樣的文件:

{
  "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"
        }
    ]
}

當屬性“section1”是用戶定義類或字典的數組時

因此,如果這是一個偶然的錯字,我會說使用一個構造良好的類是您的最佳選擇,除非這種 JSON 格式正是您真正想要的。 在這種情況下,據我所知,您可以使用字符串連接來構造格式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM