亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Unity 中的 JsonUtility 不再工作。為什么?

Unity 中的 JsonUtility 不再工作。為什么?

C#
小怪獸愛吃肉 2023-09-24 10:39:45
我正在嘗試從服務器獲取的 Json 中獲取整數值。我使用了 Unity 庫中的 JsonUtility,它運行良好。突然間它不再解析了。所有返回值均為 Null。//SAMPLE CODESpinResult res = JsonUtility.FromJson<SpinResult>(download.downloadHandler.text);spinValue = res.result;//spinValue is always 0. It was working fine//CLASS[System.Serializable]public class SpinResult{    public int result;}//JSON{    "data": {        "type": "",        "id": "",        "attributes": {            "server_seed": "",            "client_seed": "",            "result": 31,        },        "next_spin": {            "hashed_server_seed": "",            "client_seed": ""        }    }}我只需要整數“RESULT”,在本例中它應該是 31,但實際輸出始終為 0。我每次都會檢查 Json,它工作得很好。
查看完整描述

1 回答

?
至尊寶的傳說

TA貢獻1789條經驗 獲得超10個贊

我還沒有測試過這個,但嘗試讓你的類看起來像這樣:


[System.Serializable]

public class SpinResult

{

    public string type;

    public string id;

    public Attributes attributes;

}


[System.Serializable]

public class Attributes

{

    public string server_seed;

    public string client_seed;

    public int result;

}

然后要獲取您的價值,result請使用:


int spinValue = res.attributes.result;


查看完整回答
反對 回復 2023-09-24
  • 1 回答
  • 0 關注
  • 119 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號