2013-08-26 32 views
0

我在Unity3D上使用JSON.Net 5.0r6序列化對象,dotnet 2版本。我可以在編輯器構建中的Webplayer模式下正常運行,但是當我部署到Webplayer時。我收到一個丟失的例外。我可以得到相同的代碼在Android上運行良好(沒有剝離),所以它不是代碼端。Unity3D中的JSON.Net中的MissingMethodException webplayer

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

我得到了一些代碼,做原始字節數組打包,這是非常乾淨,如果你想要它? – War

回答

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