Unity3D网络播放器中JSON.Net中的MissingMethodException

时间:2013-08-26 15:02:37

标签: unity3d json.net

我在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 

2 个答案:

答案 0 :(得分:1)

发现另一个类似的问题,似乎是Unity3D再次搞砸了

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);