[Resolved]il2cpp error when use SimpleJSON in Unity 5.1

SimpleJSON script from http://wiki.unity3d.com/index.php/SimpleJSON

When scene start got error

NullReferenceException: A null value was found where an object instance was required.
at CRKnowledgeResource.Awake () [0x00000] in :0
at System.Collections.Generic.Dictionary`2+ShimEnumerator[System.Int32,System.Int32].get_Current () [0x00000] in :0

Code:
void Awake () {
var knowledges = Resources.LoadAll(“Data/Knowledges/”);
if(knowledges == null){
Debug.LogError(“not found knowledge Json in Data/Knowledges/”);
}
_knowledgeJsonList = new List();
foreach(var knowledgeJsonObj in knowledges){
JSONNode jsNode = JSON.Parse(knowledgeJsonObj.ToString());
jsNode[“slug”] = knowledgeJsonObj.name;
_knowledgeJsonDic[knowledgeJsonObj.name] = jsNode;
_knowledgeJsonList.Add(jsNode);
}
}

if i not use JSON it work

any one use json?

Is SimpleJSON compatible with IL2CPP? You may have to try a different JSON solution.

I use JSON.NET and it works in general quite well with IL2CPP. Only in Android I have an issue that’s temporarily solved disabling stripping code option.

Thrawn, you’re not the only one. I have a couple other reports with the same problem. Unity seems to have for some reason started stripping the constructor off of the TypeConverter in Android and it’s causing issues. I’m actively looking into it.

That being said, the OPs structure is simple enough something like JsonFX or JSONObject would probably work well for him and are free solutions.

I’m glad you’re investigating it and even more important that you submit bugs to Unity as well. It’s fairly common for me to submit one new bug for IL2CPP every week.

1 Like

This particular one isn’t IL2CPP related but I see plenty of those as well. :\

Today I try to use miniJSON and I found out that it’s not JSON issue but the Resources.LoadAll bug

var knowledges = Resources.LoadAll(“Data/Knowledges/”);

when if call this Resources.LoadAll
in 32 bit it load all string in each file
knowledges = [ string data in file , string data in file , string data in file, … ]

but in 64 bit it loaded file name to the array
knowledges = [ filename, filename, filename, … ]

only happen in iOS device when build with IL2CPP 64bit
Not happen in Android or run in Editor

Fix by parse to TextAsset before parse to string
var knowledges = Resources.LoadAll(“Data/Knowledges/”);
foreach(var knowledgeJsonObj in knowledges){
TextAsset knowledgeJsonAsset = (TextAsset)knowledgeJsonObj;
JSONNode jsNode = JSON.Parse(knowledgeJsonAsset.ToString());


}
Unity version Patch 5.1.1p2

1 Like