简体   繁体   中英

parsing json C# / unity3d

Struggling to find a good solution to parse this data or similar structure in Unity using C#:

 {
 "levels":{
     "level1":{
         {0,1,0,0},
         {0,0,1,0},
         {0,2,0,0},
         {0,0,0,0},
     }
  }
}

I've tried the built in Unity C# class JsonUtility and Boomlagoon plugin but havent been able to parse the data into a Levels 2 dimensional array of different Levels.

Any help would be appreicated.

You won't find any solution as this is not a valid json.

The following would be a more appropriate solution:

{
    "levels": [{
        "name": "level1",
        "data": [
            [0, 1, 0, 0],
            [0, 0, 1, 0],
            [0, 2, 0, 0],
            [0, 0, 0, 0]
        ]
    }]
 }

and the Csharp side would turn out to be :

public class Level
{
    public string name;
    public int[][]data; 
}

public class RootObject
{
    public Level[] levels;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM