团结c#json不工作

时间:2017-10-04 17:47:59

标签: c# json unity3d

我对c#和团结相当新。我试图从我的json文件中获取变量,但该程序似乎只能正确返回布尔值和字符串。

C#

public class Reputation
{
    public int normal { get; set; }
}
void Start()
{
    string reputation = @"c:\path\to\file\reputation.json";
    StreamReader reader2 = new StreamReader (reputation); 
    player.reputation = JsonUtility.FromJson<Reputation>(reader2.ReadToEnd ());
    reader.Close ();
    Debug.Log(player.reputation.normal);
}

JSON

{
    "normal":20
}

并且日志显示0

0 个答案:

没有答案