栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将Json字符串转换为C#对象列表

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将Json字符串转换为C#对象列表

您可以使用json2csharp.com将json转换为对象模型

  • 将您的JSON粘贴到Box中。
  • 单击“生成”。
  • 您将为您的对象模型获得C#代码
  • 通过
    var model = JsonConvert.DeserializeObject<RootObject>(json);
    使用 NewtonJson* 反序列化 *

在这里,它将生成如下内容:

public class MatrixModel{    public class Option    {        public string text { get; set; }        public string selectedMarks { get; set; }    }    public class Model    {        public List<Option> options { get; set; }        public int maxOptions { get; set; }        public int minOptions { get; set; }        public bool isAnswerRequired { get; set; }        public string selectedOption { get; set; }        public string answerText { get; set; }        public bool isRangeType { get; set; }        public string from { get; set; }        public string to { get; set; }        public string mins { get; set; }        public string secs { get; set; }    }    public class Question    {        public int QuestionId { get; set; }        public string QuestionText { get; set; }        public int TypeId { get; set; }        public string TypeName { get; set; }        public Model Model { get; set; }    }    public class RootObject    {        public Question Question { get; set; }        public string CheckType { get; set; }        public string S1 { get; set; }        public string S2 { get; set; }        public string S3 { get; set; }        public string S4 { get; set; }        public string S5 { get; set; }        public string S6 { get; set; }        public string S7 { get; set; }        public string S8 { get; set; }        public string S9 { get; set; }        public string S10 { get; set; }        public string ScoreIfNoMatch { get; set; }    }}

然后,您可以反序列化为:

var model = JsonConvert.DeserializeObject<List<MatrixModel.RootObject>>(json);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/575048.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号