在Unity中json文件的解析方式
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】PhpStorm配置XDebug(远程)调试PHP
- Python之列表、字符串、元组和字典的基本用法
- RSA和DES------加密和解密类
- 11g RAC R2 之Linux DNS 配置
- android124 zhihuibeijing 新闻中心-组图
- iOS中的定时器 - NSTimer 使用方法
- PC-破解RAR软件注册问题
- 【技术贴】解决QQ空间发表文章手机不显示换行
- Html和Css学习笔记-css基础知识
- /usr/bin/ld: .build_release/tools/alignment_tools.o: undefined reference to symbol &#39;omp_get_thread_num@@OMP_1.0&#39;
- 在 vue.js 中动态绑定 v-model
- Mybatis分页插件pagehelper的使用
- guzzle http异步 post
- PHPExcel 导入
- Python学习---基于JQuery的Ajax实现[快捷+底层$.ajax]
- Turkey HSD检验法/W法
- intellij-idea+maven搭建scala环境
- 淘宝TDDL配置以及使用
- 分享Win7 将svn增加系统服务并成功启动的方法
- HDU 4609 FFT模板
热门文章
- [bzoj4066/2683]简单题_KD-Tree
- Java和JS MD5加密-附盐值加密demo
- eclipse 执行MapReduce程序错误异常汇总(解决Map not fount)
- 一个NHibernate的BUG
- 霸气側漏的HTML5--之--强大的form表单
- Android 线程 Looper.prepare()、Looper.loop() 使用
- luogu1063 能量项链
- luogu1169 棋盘制作
- c# winform 多条件查找 外加网络人才回答
- B5090 组题 二分答案