gpt4 book ai didi

json - Unity 从服务器反序列化

转载 作者:行者123 更新时间:2023-12-04 00:54:17 25 4
gpt4 key购买 nike

<分区>

为了我们的高分系统,我已经尝试了几个小时来反序列化来 self 的服务器的信息。但是我收到一个错误:

ArgumentException: JSON must represent an object type.

这就是我反序列化的方式(scores 是 Scores 类型):

public void Deserialize()
{
Debug.Log("From Server is ::::: -----> " + FromServer);
scores = JsonUtility.FromJson<Scores> (FromServer);
}

这是我的服务器生成的 Json 信息。我究竟做错了什么?

 [
{
"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"
}
]

这些是我要序列化的类:

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com