小编Joh*_*ont的帖子

Unity从服务器反序列化

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

ArgumentException:JSON必须表示对象类型.

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

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

这是我的服务器生成的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"
    }, …
Run Code Online (Sandbox Code Playgroud)

serialization json unity-game-engine deserialization

3
推荐指数
1
解决办法
2344
查看次数

Unity反序列化为Scriptable对象

有谁知道为什么下面这段代码会返回错误

ArgumentException: Cannot deserialize JSON to new instances of type 'CatalogueList.'
UnityEngine.JsonUtility.FromJson[CatalogueList]
Run Code Online (Sandbox Code Playgroud)

我的目录列表存在于我的资产中,我可以完整地序列化并上传到我的服务器,我试图下载我的文件并用json填写所有字段.

这是代码.

void AddDownloadedItems(string text, CatalogueList list)
{
    CatalogueList inventoryItemList = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/CatalogueItem.asset", typeof(CatalogueList)) as CatalogueList;
    list = JsonUtility.FromJson<CatalogueList>(text);
}
Run Code Online (Sandbox Code Playgroud)

但正如我所说它只会返回错误?

CatalogueItemList代码

public class CatalogueList : ScriptableObject { 
    public List<CatalogueItem> itemList;
}
Run Code Online (Sandbox Code Playgroud)

目录项目代码

[System.Serializable]                                                           //  Our Representation of an InventoryItem
public class CatalogueItem
{
    public string databaseID;
    public string itemName = "New Item";
    public enum PrizeMachine { Bronze, Silver, Gold, Platinum };
    public PrizeMachine myMachine;                     
    public Texture2D itemThumb = …
Run Code Online (Sandbox Code Playgroud)

serialization json unity-game-engine

2
推荐指数
1
解决办法
6143
查看次数