Hey,
I am trying to decode a text file that contains json data. The problem that I’m having though is that Prime31’s Json.jsonDecode is always returning null. I have tried .txt files with Resources.Load and saving as TextAsset and I have tried .json files with www loading. The files are downloading just fine and Debug.Log displays the correct data but once I put it through jsonDecode the json object will return null. Here is my script that is downloading the file:
using Prime31;
//later on down the code
void LoadJsonFile(string filename)
{
TextAsset data = Resources.Load("Text/" + filename,typeof(TextAsset)) as TextAsset;
if(data != null)
{
TestJSON json = null;
try
{
json = Json.jsonDecode(data.text) as TestJSON;
}
catch(System.Exception e)
{
Debug.Log(e.Message);
}
//irrelevant code
}
}
I know that the json file is has a valid format because I always check it here before I start up my project:
http://jsonlint.com
In the code I have also tried doing this:
try
{
TestJSON json = Json.jsonDecode(data.text) as TestJSON;
}
catch(System.Exception e)
{
Debug.Log(e.Message);
}
But jsonDecode still returned null.
Thanks in advance for any help that you guys can give me.