使用Unity自带的解析工具完成Json数据的解析
来源:互联网 发布:mac book air 13 编辑:程序博客网 时间:2024/06/05 09:44
一、最终解析结果
二、Json数据文件
三、一些坑
Json保存的格式Unicode(UTF-8,无签名),如果有签名会报错 未测试
解析类中的字段必须和Json中的字段相对应
3. 如果想解析多条数据,改变Json字符串,先将他装在一个字段中,然后在解析
4. 解析类必须加[System.Serializable]
四、源代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using
System.Collections.Generic;
using
UnityEngine;
public
class
JsonSerializerDemo : MonoBehaviour {
void
Start () {
//AssetBundle ab = AssetBundle.LoadFromFile(Application.dataPath+ "/Resources/guidesteplist.ab");
TextAsset ta=Resources.Load<TextAsset>(
"GuideStepList"
);
if
(ta !=
null
)
{
//TextAsset ta = ab.LoadAsset<TextAsset>("guidesteplist");
string
str = ta.text;
if
(!
string
.IsNullOrEmpty(str))
{
ExampleList gstd = JsonUtility.FromJson<ExampleList>(str);
for
(
int
i = 0; i < gstd.tempList.Count; i++)
{
Debug.LogError(gstd.tempList[i].ToString());
}
}
}
else
{
Debug.LogError(
"加载不到资源"
);
}
}
}
[System.Serializable]
public
class
ExampleList
{
public
List<GuideStepData> tempList;
}
[System.Serializable]
public
class
GuideStepData
{
public
override
string
ToString()
{
return
"Data:[ID:"
+ ID +
",Type:"
+ Type +
"]"
;
}
public
int
ID;
public
string
Type;
}
阅读全文
0 0
- 使用Unity自带的解析工具完成Json数据的解析
- 使用as3.0自带JSON解析工具解析JSON数据
- 自带JSON解析工具
- ios自带的json对请求数据进行解析
- 利用android自带的JSONObject解析json数据
- Android使用自带JSONObject解析JSON数据 - jCuckoo的专栏 - 博客频道 - CSDN.NET
- 使用JDK自带的工具wsimport解析WSDL文件
- Android使用自带JSONObject解析JSON数据
- 用安卓自带的原生方法解析从webservice获取的json数据
- 用安卓自带的原生方法解析从webservice获取的json数据
- Android中JSON数据解析:系统自带JSONObject以及第三方GSON的实现
- iOS 自带的解析json的类
- 使用unity 5.3版本以上 自带Json解析器与后台进行登录验证。
- 苹果自带的json解析NSJSONSerialization(序列化)
- 调用android自带的json类解析出错!!!
- IOS开发学习27 ObjectC 自带json解析方法的使用
- Unity 使用JsonFx解析本地json数据
- json解析工具:Gson的使用
- 【NOIP2017提高A组集训10.24】合影
- 分享一个近期遇到的逻辑漏洞案例
- 算法爱好者——判断N是否为丑数 ? 待解决
- 我与SpringMVC的纠纠缠缠第三解
- FE
- 使用Unity自带的解析工具完成Json数据的解析
- 5.Spring Cloud:分布式配置中心【Dalston版】
- 动态规划 G
- 自定义View能力雷达图
- windows环境安装pip
- linux环境下安装php7
- XRecyclerView上下拉使用
- Frida官方手册
- Eclipse的设置、调优、使用(解决启动卡顿等问题)