i'm currently trying to save a n x m field array as json in a text file. I know unity doesn't support array types for top-level JSON deserialization. Therefore i have made a class which looks like this
public class Field{
public int[][] id;
public GameObject[][] gameObjectReference;
}
Wether the GameObject Array is stored in the json file isn't relevant but i still would like to save the id array. So far i have this code snipet to test this.
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));
But the console just says:
{}
The File im curretnly using looks something like this
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
What's wrong with my approach? pls help! i just cant figure it out.