Unity 复杂Json 解析
最近项目需要, 搞了一串嵌套非常多的Json 用LitJson读取体验不太好,上网查了一下发现NetwtonsoftJson ,十分好用
一句代码就可以了
JObject data = JsonConvert.DeserializeObject<JObject>(message);
其实也可以用LitJson方法
主要用法是把Json文件 格式化,然后搞清楚层级结构关系,创建一个对应类就可以直接转换了
APPStore appStore = JsonMapper.ToObject<APPStore>(message);
需要根据Json结构建好一个类 例如:
public class APPStore
{
public List<Category> data { get; set; }
}
public class Category
{
public int id { get; set; }
public int pid { get; set; }
public string name { get; set; }
public int special { get; set; }
public List<AppCategory> child { get; set; }
}
public class AppCategory
{
public int id { get; set; }
public int pid { get; set; }
public string name { get; set; }
public int special { get; set; }
public List<AppData> child { get; set; }
}

浙公网安备 33010602011771号