我在Unity3D,dotnet 2版本上使用JSON.Net 5.0r6序列化对象。我可以在编辑器构建中以Webplayer模式运行它,但是当我部署到Webplayer时。我得到一个遗漏的例外。我可以在Android上运行相同的代码(没有剥离),所以它不是代码端。
MissingMethodException: Method not found: 'System.Collections.ObjectModel.KeyedCollection<System.String,Newtonsoft.Json.Serialization.JsonProperty>..ctor'.
at Newtonsoft.Json.Serialization.JsonObjectContract..ctor (System.Type underlyingType) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract (System.Type objectType) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe (System.Object value) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, System.Type type, Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0
答案 0 :(得分:1)
http://forum.unity3d.com/threads/133505-webplayer-and-System-Collections-ObjectModel-KeyedCollection
答案 1 :(得分:0)
不幸的是,在JSON.Net中使用KeyedCollection
(最初在mscorlib中)时存在问题。
我的解决方案是用LitJson.dll
替换整个实现我从JSON.Net实际使用的唯一两种方法是
//JSON.Net
JsonConvert.DeserializeObject<YourClass>(jsonSring);
JsonConvert.SerializeObject(yourObject);
您可以使用
轻松更改它们 //LitJson
JsonMapper.ToObject<YourClass>(jsonSring);
JsonMapper.ToJson(yourObject);