0

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

2 回答 2

1

又发现了一个类似的问题,好像是Unity3D又搞砸了

http://forum.unity3d.com/threads/133505-webplayer-and-System-Collections-ObjectModel-KeyedCollection

于 2013-08-26T15:25:09.710 回答
0

不幸的是KeyedCollection,在 JSON.Net 中实现的(最初在 mscorlib 中)的使用存在问题。

我的解决方案是用LitJson.dll替换整个实现

我从 JSON.Net 实际使用的仅有的两种方法是

    //JSON.Net
    JsonConvert.DeserializeObject<YourClass>(jsonSring);
    JsonConvert.SerializeObject(yourObject);

你可以很容易地改变它们

    //LitJson
    JsonMapper.ToObject<YourClass>(jsonSring);
    JsonMapper.ToJson(yourObject);
于 2014-11-28T15:46:43.413 回答