600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > LitJson 将json 解析为C#类

LitJson 将json 解析为C#类

时间:2023-11-13 06:59:14

相关推荐

LitJson 将json 解析为C#类

Json 文件

[

{

"ID" : 10001,

"Type" : 8,

"QuickMark" : 1,

"MarkClass" : "HousePropertyData",

"ShowConditional" : 1,

"Conditionals" : ["前往指定房屋位置"],

"ShowSchedule" : 0,

"Schedule" : "",

"ShowTips" : 0

},

{

"ID" : 10002,

"Type" : 4,

"QuickMark" : 0,

"MarkClass" : "",

"ShowConditional" : 1,

"Conditionals" : ["购买" , "套房"],

"ShowSchedule" : 0,

"Schedule" : "",

"ShowTips" : 0

},

{

"ID" : 10003,

"Type" : 1,

"QuickMark" : 1,

"MarkClass" : "MapTagData",

"ShowConditional" : 0,

"Conditionals" : [],

"ShowSchedule" : 0,

"Schedule" : "",

"ShowTips" : 0

},

{

"ID" : 10004,

"Type" : 6,

"QuickMark" : 0,

"MarkClass" : "",

"ShowConditional" : 1,

"Conditionals" : ["购买" , "辆车"],

"ShowSchedule" : 1,

"Schedule" : "0/1",

"ShowTips" : 0

},

{

"ID" : 10005,

"Type" : 9,

"QuickMark" : 1,

"MarkClass" : "GarageData",

"ShowConditional" : 0,

"Conditionals" : [],

"ShowSchedule" : 0,

"Schedule" : "",

"ShowTips" : 0

}

]

在c#中先按Json的字段,对应写一个c#类,(属性名对应,不然转类属性会找不到)

public class GuideDataByJson{public int ID;public int Type;public int QuickMark;public string MarkClass;public int ShowConditional;public string[] Conditionals;public int ShowSchedule;public string Schedule;public int ShowTips;}

转义

var json = Resources.Load<TextAsset>("data/GuideJson").text;// 加载json文件JsonData = JsonMapper.ToObject<List<GuideDataByJson>>(json);// 将Json文件对应转化为多个类型,JsonData 可以看作一个list

使用

例:

var Id = 10001;var dataByJson = JsonData.Find(x => x.ID == Id);

Log.Debug(dataByJson.QuickMark);// 1

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。