Unity3d 下的 Json.NET for iOS [英] Json.NET under Unity3d for iOS

查看:24
本文介绍了Unity3d 下的 Json.NET for iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人成功地将 Json.NET 改编/移植到能够在部署到 iOS 的 Unity3d 下运行的版本(以及网络播放器和 android,但这些问题似乎不那么严重),以某种方式克服了那里的 AOT 问题?

has anyone succeeded to adapt/port Json.NET to a version able to run under Unity3d deployed to iOS (and the webplayer, and android, too, but these seem less problematic), somehow overcoming the AOT issues there?

或者是否计划发布兼容版本的 Json.NET?

Or are there plans to release a compatible version of Json.NET?

非常感谢,

最大

推荐答案

您可以使用 netstandard 版本的 Newtonsoft.Json 在 Unity 中,它工作正常.看来这个库已经改变了一些内部实现,不再使用 System.Reflection.Emit 进行反序列化.请确保在下载 nuget 包后,您会从 netstandard2.0 文件夹而不是从 net45 获得 Newtonsoft.Json.dll.并且不要忘记在 link.xml 中指定 System.Linq.Expressions.Interpreter.LightLambda 类不应被剥离(它用于反序列化)以及用于反序列化的库/类(以保留构造函数).您的 link.xml 应该看起来像这样:

You can use netstandard version of Newtonsoft.Json in Unity and it works fine. It seams that this library has changed some inner implementations to not use System.Reflection.Emit for deserialization anymore. Just be sure that after downloading nuget package you get Newtonsoft.Json.dll from netstandard2.0 folder, not from net45. And also don't forget to specify in link.xml that System.Linq.Expressions.Interpreter.LightLambda class shouldn't be stripped (it's used for deserialization) along with libraries/classes that you use for deserialization (to preserve constructors). Your link.xml should look smth like this:

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

我们在 Android 和 iOS 的所有项目中使用这个库,使用 IL2CPP 和 Mono 运行时.此外,与 Unity 的 JsonUtility 不同,Newtonsoft.Json 完全支持任何类型的对象,包括 Dictionary.

We use this library in all our projects for Android and iOS with IL2CPP and Mono runtimes. Moreover, unlike Unity's JsonUtility, Newtonsoft.Json fully supports any type of objects, including Dictionary.

微软示例

这篇关于Unity3d 下的 Json.NET for iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆