Json deserialisation of server results?

Hi there,

I have been trying for a couple hours to deserialize info from my server for our high score system. Everytime i try to i will get n error “ArgumentException: JSON must represent an object type.”

This is my Json info which is generated by my server when i echo it out. What am i doing wrong?

 [
    {
        "ScoreID": "8",
        "GoogleID": "asasda",
        "Score": "258"
    },
    {
        "ScoreID": "11",
        "GoogleID": "kjjahushcjkasjkcajskndas",
        "Score": "258"
    },
    {
        "ScoreID": "10",
        "GoogleID": "aakhskjbjkabsjjkasd",
        "Score": "258"
    },
    {
        "ScoreID": "9",
        "GoogleID": "mnbabksgkajsd",
        "Score": "258"
    },
    {
        "ScoreID": "13",
        "GoogleID": "kajiuskabkjshdkhausd",
        "Score": "258"
    },
    {
        "ScoreID": "7",
        "GoogleID": "asasdas,mgkhgjhbhjaf",
        "Score": "258"
    },
    {
        "ScoreID": "6",
        "GoogleID": "ss",
        "Score": "258"
    },
    {
        "ScoreID": "5",
        "GoogleID": "kljkuasjkba",
        "Score": "258"
    },
    {
        "ScoreID": "4",
        "GoogleID": "asdadasdasdasdw",
        "Score": "258"
    },
    {
        "ScoreID": "3",
        "GoogleID": "asdadsasd",
        "Score": "258"
    },
    {
        "ScoreID": "2",
        "GoogleID": "kbaskjkjsbnkjas",
        "Score": "258"
    },
    {
        "ScoreID": "12",
        "GoogleID": "lahaushyuiahkjsjksd",
        "Score": "258"
    },
    {
        "ScoreID": "1",
        "GoogleID": "254asdasd54a5s1das2d1as54d",
        "Score": "259"
    },
    {
        "ScoreID": "14",
        "GoogleID": "kjaskjhjkahsjkdnjkasd",
        "Score": "6859"
    }
]

and this is the classes im trying to serialise into

[System.Serializable]
public class LeaderBoardEntries
{
    public int ScoreID;
    public string GoogleID;
    public int Score;
}
[System.Serializable]
public class Scores
{
    public List<LeaderBoardEntries> scores;
}

“ArgumentException: JSON must represent an object type.”

an object type in json is a {}.
your json is a , which is an array.

if you’re able to change the server code,
modify it to emit something like

{
  "scores": [
    {
      "ScoreID": "1",
      "GoogleID": "254asdasd54a5s1das2d1as54d",
      "Score": "259"
    },
    {
      "ScoreID": "12",
      "GoogleID": "lahaushyuiahkjsjksd",
      "Score": "258"
    }
  ]
}

if you’re not able to modify the server code, have your client modify the json string before parsing. eg

string newJSONString = "{ \"scores\": " + oldJSONString + " }";

… i would strongly advise trying to to it on the server, tho.

also, unrelatedly,
if it were me i would rename your “LeaderBoardEntries” class to “LeaderBoardEntry”.