0

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.

2
  • I can do it with Regex. Commented Jun 5, 2016 at 13:15
  • stackoverflow.com/questions/13469765/… Commented Jun 5, 2016 at 13:51

1 Answer 1

3

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.