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