- Home /
Json Serialization documentation official Unity website - marking it [Serializable] caused error
Hi all, I am trying to read data from a json file. I see the official documentation here covers it: https://docs.unity3d.com/Manual/JSONSerialization.html
but as soon as I add [Serializable] to my code, it chucks up a error. The example in the link above states it should be marked as Serializable:
[Serializable]
public class MyClass
{
public int level;
public float timeElapsed;
public string playerName;
}
But here is the error I get:
Assets/Scripts/DataReader.cs(5,2): error CS0246: The type or namespace name `Serializable' could not be found. Are you missing an assembly reference?
It doesnt mention any assembly references in the page. Im hoping the page is wrong lol, my class
Answer by carlos170586001500 · Aug 15, 2017 at 04:29 PM
[System.Serializable]
aha perfect! I actually used using System; at the top , hopefully I can get this Json data in my game now :) thank you