using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using LitJson;
using System.IO;
using System.Text; public class JsonDate<T>
{ private static JsonDate<T> instance; private JsonDate()
{
//filePath = Application.streamingAssetsPath + "/Data.json";
} public static JsonDate<T> GetInstance()
{
if (null == instance)
{
instance = new JsonDate<T>();
}
return instance;
} public List<T> GetJsonInfo(string data,string filePath)
{ string str = File.ReadAllText(filePath, Encoding.UTF8);
JsonData id = JsonMapper.ToObject(str);
JsonData levels = id[data];
string LevelStr = JsonMapper.ToJson(levels);
T[] rows = JsonMapper.ToObject<T[]>(LevelStr);
if (rows.Length > 0)
{
return new List<T>(rows);
}
return null; } }

  

//解复杂json文件
public void GetJsonInfo()
{

string filename = Application.streamingAssetsPath + "/data.json";
string str = File.ReadAllText(filename);
JsonData id = JsonMapper.ToObject(str);
JsonData levels = id["TestData"];
string LevelStr = JsonMapper.ToJson(levels);
Jsonaa[] rows = JsonMapper.ToObject<Jsonaa[]>(LevelStr);
list = new List<Jsonaa>(rows);
for(int i=0;i<list.Count;++i)
{
Debug.Log(list[i].ID);
}
}

//解简单Json文件
public List<T> LoadAll()
{
string str = File.ReadAllText(filePath);
T[] rows = JsonMapper.ToObject<T[]>(str);
if(rows.Length>0)
{
return new List<T>(rows);
}
return null;
}

    public void Save(List<T> data)
{
string str = JsonMapper.ToJson(data);
File.WriteAllText(filePath, str);
}
}

  

最新文章

  1. 【总结1】PhpStorm配置XDebug(远程)调试PHP
  2. Python之列表、字符串、元组和字典的基本用法
  3. RSA和DES------加密和解密类
  4. 11g RAC R2 之Linux DNS 配置
  5. android124 zhihuibeijing 新闻中心-组图
  6. iOS中的定时器 - NSTimer 使用方法
  7. PC-破解RAR软件注册问题
  8. 【技术贴】解决QQ空间发表文章手机不显示换行
  9. Html和Css学习笔记-css基础知识
  10. /usr/bin/ld: .build_release/tools/alignment_tools.o: undefined reference to symbol &#39;omp_get_thread_num@@OMP_1.0&#39;
  11. 在 vue.js 中动态绑定 v-model
  12. Mybatis分页插件pagehelper的使用
  13. guzzle http异步 post
  14. PHPExcel 导入
  15. Python学习---基于JQuery的Ajax实现[快捷+底层$.ajax]
  16. Turkey HSD检验法/W法
  17. intellij-idea+maven搭建scala环境
  18. 淘宝TDDL配置以及使用
  19. 分享Win7 将svn增加系统服务并成功启动的方法
  20. HDU 4609 FFT模板

热门文章

  1. [bzoj4066/2683]简单题_KD-Tree
  2. Java和JS MD5加密-附盐值加密demo
  3. eclipse 执行MapReduce程序错误异常汇总(解决Map not fount)
  4. 一个NHibernate的BUG
  5. 霸气側漏的HTML5--之--强大的form表单
  6. Android 线程 Looper.prepare()、Looper.loop() 使用
  7. luogu1063 能量项链
  8. luogu1169 棋盘制作
  9. c# winform 多条件查找 外加网络人才回答
  10. B5090 组题 二分答案