How I understand all that works on mono, should work on il2cpp (I mean beck end mono and il2cpp)!
But now I have a problems with JSOn deserialization, I use JsonFx, and all work fine if I set mono in backend,
but when I set il2cpp I see in xCode console next message:
[SIZE=2]MissingMethodException: Method not found: 'Default constructor not found...ctor() of System.ComponentModel.Int32Converter'.
at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
at System.ComponentModel.TypeDescriptor.GetConverter (System.Type type) [0x00000] in <filename unknown>:0
at JsonFx.Json.TypeCoercionUtility.CoerceType (System.Type targetType, System.Object value) [0x00000] in <filename unknown>:0
at JsonFx.Json.JsonReader.ReadNumber (System.Type expectedType) [0x00000] in <filename unknown>:0
at JsonFx.Json.JsonReader.Read (System.Type expectedType, Boolean typeIsHint) [0x00000] in <filename unknown>:0
at JsonFx.Json.JsonReader.ReadObject (System.Type objectType) [0x00000] in <filename unknown>:0
at JsonFx.Json.JsonReader.Read (System.Type expectedType, Boolean typeIsHint) [0x00000] in <filename unknown>:0
at JsonFx.Json.JsonReader.Deserialize (Int32 start, System.Type type) [0x00000] in <filename unknown>:0
at JsonFx.Json.JsonReader.Deserialize (System.String value, Int32 start, System.Type type) [0x00000] in <filename unknown>:0
at TestJSON.TestJSONSerialize () [0x00000] in <filename unknown>:0
at TestJSON.TestJSONSerialize () [0x00000] in <filename unknown>:0
at TestJSON.Start () [0x00000] in <filename unknown>:0 [/SIZE]
This is TestJSON.cs script that I use for test
[SIZE=2]using UnityEngine;
using System.Collections;
using JsonFx.Json;
[SerializeField]
public class JSonTestClass
{
public int indexInt;
public float indexFloat;
public string name;
public int[] array;
public string ToString()
{
return indexInt + " " + indexFloat + " " + name + " " + array.Length;
}
}
public class TestJSON : MonoBehaviour
{
void Start()
{
TestJSONSerialize ();
}
void TestJSONSerialize()
{
JSonTestClass jsonTest = new JSonTestClass();
jsonTest.indexInt = 23;
jsonTest.indexFloat = 95.12f;
jsonTest.name = "testName";
jsonTest.array = new int[5];
for(int i = 0; i< 5; i++)
jsonTest.array[i] = i;
string jsonString = JsonWriter.Serialize(jsonTest);
Debug.Log(jsonString);
JSonTestClass jSonDeseriazlie = JsonReader.Deserialize<JSonTestClass>(jsonString);
Debug.Log("After Serialize " + jSonDeseriazlie.ToString());
}
}[/SIZE]
Is it Bug or not?
If I right understand about il2cpp, if code work with mono backEnd, this code also MUST work with il2cpp right?
Wrong. Not everything that works on mono works with IL2CPP.
IL2CPP is AOT only and in your case JsoxFX is known to work badly on iOS (AOT platform) because it uses JIT features so it wont probably work well with IL2CPP either unless there is an updated version out there.
Newtonsoft.Json does also not work. It gives me also an error. @DziDAI Does it also not work for you?
Iāam using now the JSONObject from the wiki with a custom deserializer for my datastructure. http://wiki.unity3d.com/index.php/Json
Its a very bad solution for me because if the datastructure changes i have always to change the deserializer too.
I havenāt looked at jsonfx so Iām not sure why it wouldnāt work. However, my json .net for unity asset does work as of unity 5 beta 20 and the newest 4.6 patch release.
What platform are you building for? Iām assuming by newtonsoft you guys mean my port and not the official. If its ios64-bit it should just work. If its webgl, send me a pm with your invoice number and ill send you an update with the proper directives for webgl.
Ahh yeah that will never work. Itās not aot compatible. In fact it wont work with anything except desktop standalone builds and in the editor. Thatās why I made the port.
Our problem with the āDefault constructor not foundā¦ctor()ā was solved with a slight code adjustment. So while switching JSON libraries might work for some (who have a budget and time to do soā¦), hopefully others will find our solution viable.
Our issue was that the System. Activator.CreateInstance function was failing to find a default constructor for an array of custom class. This was solved by swapping references to System. Activator.CreateInstance with references to System.Array.CreateInstance and passing the ElementType instead of the Type. An array of the correct type was then created, and populated with our data from JSON just like when we compiled with Mono. Additionally, this solution worked for us within Mono compiler and within the IL2CPP so for any struggling with Abstracted Types and JSON parsing; there is a solution.