【发布时间】:2017-04-18 12:28:37
【问题描述】:
我目前正在尝试将 n x m 字段数组保存为文本文件中的 json。 我知道统一不支持顶级 JSON 反序列化的数组类型。因此我做了一个看起来像这样的类
public class Field{
public int[][] id;
public GameObject[][] gameObjectReference;
}
GameObject 数组是否存储在 json 文件中无关紧要,但我仍然想保存 id 数组。到目前为止,我有这个代码片段来测试它。
String[] aRows = System.IO.File.ReadAllLines(pathToSomeFile);
field = new Field ();
field.id = new int[aRows [0].Split(';').Length][];
for (int i = 0; i < aRows [0].Split(';').Length; i++) {
field.id [i] = new int[aRows.Length];
}
for (int y = 0; y < aRows.Length; y++) {
for (int x = 0; x < aRows[y].Split(';').Length; x++) {
field.id [x] [y] = int.Parse(aRows[y].Split(';')[x]);
}
}
GameManager.log (JsonUtility.ToJson (field));
但控制台只是说:
{}
我当前使用的文件看起来像这样
5;5;5;5;5;5;5;5;5
5;5;5;5;5;5;5;5;5
5;5;5;5;5;5;5;5;5
5;5;5;5;5;5;5;5;5
5;5;5;5;5;5;5;5;5
5;5;5;5;5;5;5;5;5
我的方法有什么问题?请帮忙!我就是想不通。
【问题讨论】:
标签: c# arrays json unity3d unity5