简体   繁体   English

System.NotSupportedException 试图从 Unity3d/Oculus 中的 JSON 反序列化 Vector3

[英]System.NotSupportedException trying to deserialize Vector3 from JSON in Unity3d/Oculus

I am currently trying to deserialize a json string of type Vector3[][] for Unity (for a virtual reality project) and it is throwing the exception above.我目前正在尝试为 Unity(用于虚拟现实项目)反序列化 Vector3[][] 类型的 json 字符串,它抛出了上面的异常。 My json string is as follows:我的 json 字符串如下:

[[{"x":-2.343096,"y":1.72245443,"z":0.0,"normalized":{"x":-0.805718362,"y":0.592298865,"z":0.0,"magnitude":1.0,"sqrMagnitude":1.0},"magnitude":2.9080832,"sqrMagnitude":8.456948},{"x":-2.343096,"y":1.72245443,"z":0.0,"normalized":{"x":-0.805718362,"y":0.592298865,"z":0.0,"magnitude":1.0,"sqrMagnitude":1.0},"magnitude":2.9080832,"sqrMagnitude":8.456948},{"x":-2.30125523,"y":1.61087871,"z":0.0,"normalized":{"x":-0.819231868,"y":0.573462367,"z":0.0,"normalized":{"x":-0.8192319,"y":0.5734624,"z":0.0,"magnitude":1.0,"sqrMagnitude":1.00000012},"magnitude":0.99999994,"sqrMagnitude":0.99999994},"magnitude":2.80904,"sqrMagnitude":7.89070559},{"x":-2.24546719,"y":1.4853555,"z":0.0,"normalized":{"x":-0.834037364,"y":0.5517079,"z":0.0,"magnitude":1.0,"sqrMagnitude":0.99999994},"magnitude":2.692286,"sqrMagnitude":7.248404},{"x":-2.21757317,"y":1.38772666,"z":0.0,"normalized":{"x":-0.8476986,"y":0.5304781,"z":0.0,"magnitude":1.0,"sqrMagnitude":1.0},"magnitude":2.61599231,"sqrMagnitude":6.843416},{"x":-2.17573214,"y":1.27615035,"z":0.0,"normalized":{"x":-0.8625732,"y":0.5059323,"z":0.0,"magnitude":1.0,"sqrMagnitude":1.0},"magnitude":2.522374,"sqrMagnitude":6.36237},{"x":-2.147838,"y":1.17852151,"z":0.0,"normalized":{"x":-0.8766962,"y":0.481044352,"z":0.0,"magnitude":1.0,"sqrMagnitude":0.99999994},"magnitude":2.4499228,"sqrMagnitude":6.00212145},{"x":-2.09205,"y":0.997210741,"z":0.0,"normalized":{"x":-0.90269357,"y":0.430284023,"z":0.0,"magnitude":1.0,"sqrMagnitude":1.0},"magnitude":2.317564,"sqrMagnitude":5.371103},{"x":-2.05020928,"y":0.829846859,"z":0.0,"normalized":{"x":-0.926946759,"y":0.375192851,"z":0.0,"magnitude":1.0,"sqrMagnitude":0.99999994},"magnitude":2.21178746,"sqrMagnitude":4.892004},{"x":-2.02231526,"y":0.6764293,"z":0.0,"normalized":{"x":-0.9483558,"y":0.3172085,"z":0.0,"magnitude":1.0,"sqrMagnitude":0.99999994},"magnitude":2.13244367,"sqrMagnitude":4.5473156},{"x":-1.99442124,"y":0.5230123,"z":0.0,"normalized":{"x":-0.967293262,"y":0.253660679,"z":0.0,"magnitude":1.0,"sqrMagnitude":1.0},"magnitude":2.061858,"sqrMagnitude":4.251258},{"x":-1.99442124,"y":0.383542776,"z":0.0,"normalized":{"x":-0.982006431,"y":0.1888475,"z":0.0,"magnitude":1.0,"sqrMagnitude":1.0},"magnitude":2.03096557,"sqrMagnitude":4.124821},{"x":-1.980474,"y":0.230125785,"z":0.0,"normalized":{"x":-0.99331665,"y":0.115420744,"z":0.0,"normalized":{"x":-0.9933167,"y":0.115420751,"z":0.0,"magnitude":1.0,"sqrMagnitude":1.0},"magnitude":0.99999994,"sqrMagnitude":0.99999994},"magnitude":1.99379921,"sqrMagnitude":3.97523522}],[{"x":-0.9344492,"y":-4.748954,"z":0.0,"normalized":{"x":-0.193067357,"y":-0.9811855,"z":0.0,"magnitude":1.0,"sqrMagnitude":1.0},"magnitude":4.84001637,"sqrMagnitude":23.4257584},{"x":-0.9344492,"y":-4.748954,"z":0.0,"normalized":{"x":-0.193067357,"y":-0.9811855,"z":0.0,"magnitude":1.0,"sqrMagnitude":1.0},"magnitude":4.84001637,"sqrMagnitude":23.4257584}],[{"x":0.7112968,"y":-4.66527176,"z":0.0,"normalized":{"x":0.1507245,"y":-0.988575757,"z":0.0,"normalized":{"x":0.150724515,"y":-0.9885758,"z":0.0,"magnitude":1.0,"sqrMagnitude":1.0},"magnitude":0.99999994,"sqrMagnitude":0.9999999},"magnitude":4.719185,"sqrMagnitude":22.2707043},{"x":0.7112968,"y":-4.66527176,"z":0.0,"normalized":{"x":0.1507245,"y":-0.988575757,"z":0.0,"normalized":{"x":0.150724515,"y":-0.9885758,"z":0.0,"magnitude":1.0,"sqrMagnitude":1.0},"magnitude":0.99999994,"sqrMagnitude":0.9999999},"magnitude":4.719185,"sqrMagnitude":22.2707043}]]

I am using the code:我正在使用代码:

Vector3[][] allLines = JsonConvert.DeserializeObject<Vector3[][]>(jsonString);

Why does this exception usually happen?为什么通常会发生这种异常?

Exception Screenshot异常截图

System.NotSupportedException: System.Reflection.Emit.DynamicMethod::ctor
at System.Reflection.Emit.DynamicMethod..ctor (System.String name; System.Type returntype. System.Type[] paremeterTypes, System.Type [...]
at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDynamicMethod [...]
At "" CreatenewLoist
At "" CreateList
At "" CreateValueInternal
At "" Desiarilize
At "" DeserializeInternal
at "" DeserializeObject
at "" DeserializeObject[T]
at Draw.Start

Ok Guys.好了朋友们。 It worked.有效。 So I did exactly what the post said that @dbc linked:所以我完全按照帖子所说的@dbc链接:

  1. Get the \unityprojects\football\Packages\Newtonsoft.Json.13.0.1\lib\net20\Newtonsoft.json.dll file where "football" is the projectname.获取 \unityprojects\football\Packages\Newtonsoft.Json.13.0.1\lib\net20\Newtonsoft.json.Z06416233FE5EC4C59333122E4AB248 文件名为“文件名”。

  2. Put it into the folder \assemblies\AOT folder in the unityproject放入unityproject中的文件夹\assemblies\AOT文件夹中

  3. Create the "link.xml" file and put it into the assets folder with the following content:创建“link.xml”文件并将其放入 assets 文件夹,内容如下:

     <linker> <assembly fullname="Your.Dto.Package.Name" preserve="all" /> <assembly fullname="System.Core"> <type fullname="System.Linq.Expressions.Interpreter.LightLambda" preserve="all" /> </assembly></linker>

Hope that helps if someone has the same problem.如果有人遇到同样的问题,希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM