0

I'm fairly new to c# and unity. I am attempting to get variables from my json files but the program seems to only return booleans and strings properly.

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
}

and the log displays a 0

code11
  • 1,986
  • 5
  • 29
  • 37
Tyler Silva
  • 411
  • 6
  • 14
  • 1
    See *"4.TROUBLESHOOTING JsonUtility:" from the answer in the duplicate. I can spot few issues already such as the use of `{ get; set; }` and no presence of `[Serializable]`. There may be other issues in your code. – Programmer Oct 04 '17 at 17:52
  • removing {get; set;} worked, but i figured i should let you know that "The type or namespace name `serializable' could not be found. Are you missing an assembly reference?" – Tyler Silva Oct 04 '17 at 18:06
  • It's `Serializable` not `serializable` and you must import `System` namespace or use `System.Serializable` directly. – Programmer Oct 04 '17 at 18:11

0 Answers0