weilaixiaoshi
未来小师
采纳率83.3%
2019-05-17 16:37 阅读 702

求助,C# Json序列化(嵌套)

10

需要用C#生成如下的json数据,求C#代码。

可能需要用到的引用:using System.Web.Script.Serialization;

{
    "state":"ok",
    "row":21,
    "col":19,
    "firstData":[
        "会议日期",
        "会议时间",
        "星期",
        "第一会议室",
        "第二会议室",
        "第三会议室"
    ],
    "tableData":[
        {
            "meetingDate":"2019-01-05",
            "meetingTime":"14:30",
            "meetingWeek":"周一",
            "otherData":[
                {
                    "meetingRng":[
                        {
                            "meetingCase":"会议主题1",
                            "meetingRem":"会议备注"
                        }
                    ],
                    "meetingName1":"张三",
                    "meetingName2":"李四",
                    "meetingName3":"王五"
                },
                {
                    "meetingRng":[
                        {
                            "meetingCase":"会议主题2",
                            "meetingRem":"会议备注"
                        }
                    ],
                    "meetingName1":"张三1",
                    "meetingName2":"李四2",
                    "meetingName3":"王五3"
                }
            ]
        },
        {
            "meetingDate":"2019-01-05",
            "meetingTime":"16:30",
            "meetingWeek":"周一",
            "otherData":[
                {
                    "meetingRng":[
                        {
                            "meetingCase":"会议主题2",
                            "meetingRem":"一个备注"
                        }
                    ],
                    "meetingName1":"赵六",
                    "meetingName2":"马二",
                    "meetingName3":"许可"
                }
            ]
        }
    ]
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    qq_31839695 90e家 2019-05-17 17:14

    这样定义,序列化就能对应上了,好无聊的感觉,搞错了,应该用List集合去存,自己没事重新改一下吧``,自己没事

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace JsonTest
    {
    class Program
    {
    static void Main(string[] args)
    {
    }
    }

    public class table1 
    {
        public string state { get; set; }
        public string row { get; set; }
        public string col { get; set; }
        public string[] firstData;
        public tableData[] tableData;
    }
    
    public class tableData 
    {
        public string meetingDate { get; set; }
        public string meetingTime { get; set; }
        public string meetingWeek { get; set; }
        public  List<otherData> otherData;
    }
    public class otherData 
    {
        public meetingRng[] meetingRng;
        public string meetingName1 { get; set; }
        public string meetingName2 { get; set; }
        public string meetingName3 { get; set; }
    }
    public class meetingRng
    {
        public string meetingCase { get; set; }
        public string meetingRem { get; set; }
    
    
    }
    

    }

    点赞 1 评论 复制链接分享
  • smallRXD 坐地阎罗 2019-05-17 17:17

    public class Rootobject
    {
    public string state { get; set; }
    public int row { get; set; }
    public int col { get; set; }
    public string[] firstData { get; set; }
    public Tabledata[] tableData { get; set; }
    }

    public class Tabledata
    {
    public string meetingDate { get; set; }
    public string meetingTime { get; set; }
    public string meetingWeek { get; set; }
    public Otherdata[] otherData { get; set; }
    }

    public class Otherdata
    {
    public Meetingrng[] meetingRng { get; set; }
    public string meetingName1 { get; set; }
    public string meetingName2 { get; set; }
    public string meetingName3 { get; set; }
    }

    public class Meetingrng
    {
    public string meetingCase { get; set; }
    public string meetingRem { get; set; }
    }

    点赞 1 评论 复制链接分享

相关推荐