我正在嘗試從服務器獲取的 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;
- 1 回答
- 0 關注
- 119 瀏覽
添加回答
舉報
0/150
提交
取消