public void FromJson() { var target = new Target() { Targets = { new Target1(), new Target2() } }; var binder = new ConvertTypeNameBinder(); JsonSerializerSettings settings = JsonNetUtility.CreateDefault(); settings.SerializationBinder = binder; binder.Provider.Add <Target1>("target1"); binder.Provider.Add <Target2>("target2"); string result = JsonNetUtility.ToJson(target, settings); var result2 = JsonNetUtility.FromJson <Target>(result, settings); Assert.NotNull(result2); Assert.IsNotEmpty(result2.Targets); Assert.AreEqual(2, result2.Targets.Count); }
public void FromJson() { string text = Resources.Load <TextAsset>("data1").text; var target = JsonNetUtility.FromJson <Target3>(text); var target2 = (Target3)JsonNetUtility.FromJson(text, typeof(Target3)); Assert.AreEqual(1515, target.IntValue); Assert.AreEqual(false, target.BoolValue); Assert.AreEqual(5.5, target.FloatValue); Assert.AreEqual(1515, target2.IntValue); Assert.AreEqual(false, target2.BoolValue); Assert.AreEqual(5.5, target2.FloatValue); }