Newtonsoft.Json 适用于 Unity 编辑器,但不适用于移动设备
Newtonsoft.Json works in Unity Editor but not on mobile devices
我正在 Unity 中按类别编写问答游戏。这些类别是通过 returns 一个 JSON 文本的 PHP 脚本获得的,* 当我在 UnityEditor 中使用此解决方案时它工作正常,但是当我安装 . apk 在我的移动设备上,反序列化不起作用*.
与 mysql 数据库的连接和 PHP 脚本工作正常,因为在我登录之前它工作正常
string json = [
{ "id_cat":"1",
"nombre_cat":"DAM",
"id_cat_padre":"0"
},
{ "id_cat":"4",
"nombre_cat":"ASIR",
"id_cat_padre":"0"
},
{ "id_cat":"5",
"nombre_cat":"DAW",
"id_cat_padre":"0"
}
]
然后我将此字符串转换为类别列表
lsSubCategorias = JsonConvert.DeserializeObject<List<Categoria>>(json, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
我已经在代码中添加了痕迹,它就在它停止的那一行。
我使用 NuGet 安装了 Newtonsoft.Json,它出现在参考文献中。
我也只处理了一个类别对象而不是列表,但它也不起作用。
这不是可视化问题,因为我已经创建了类别对象并使用它们创建了按钮。
问题是它可以在 Unity Editor 中运行,但在我的 android 设备上不起作用
我的手机出现以下错误:
输入错误:System.PlatformNotSupportedException
ToString错误():Error.ToString()
I Installed the Newtonsoft.Json using the NuGet and it appears in the references.
Unity3d il2cpp 目标(如移动设备)不支持来自 NuGet 的 Newtonsoft.Json。使用资产商店的 Newtonsoft.Json 分支,例如 this one.
@DoctorPangloss 的回答 Newtonsoft.Json 在使用 IL2CPP 脚本后端构建时遇到了问题。这是因为 Newtonsoft.Json 没有任何完全支持 AOT 的可用版本。
有很多提供 Newtonsoft.Json 支持 AOT 的第三方解决方案。 ParentElement 的链接 JSON .NET 是一个很好的解决方案,但是该项目已经死了几年了,并且只提供了 Newtonsoft.Json 到版本 8.0.3。
我建议查看我的存储库,交付 Newtonsoft.Json 最高版本 12.0.3(在撰写本文时)并通过内置的 Unity 包管理器交付:https://github.com/jilleJr/Newtonsoft.Json-for-Unity#readme
要了解更多信息,请从 Newtonsoft.Json 的上下文中阅读我关于 What even is AOT? 的 post。
我正在 Unity 中按类别编写问答游戏。这些类别是通过 returns 一个 JSON 文本的 PHP 脚本获得的,* 当我在 UnityEditor 中使用此解决方案时它工作正常,但是当我安装 . apk 在我的移动设备上,反序列化不起作用*.
与 mysql 数据库的连接和 PHP 脚本工作正常,因为在我登录之前它工作正常
string json = [
{ "id_cat":"1",
"nombre_cat":"DAM",
"id_cat_padre":"0"
},
{ "id_cat":"4",
"nombre_cat":"ASIR",
"id_cat_padre":"0"
},
{ "id_cat":"5",
"nombre_cat":"DAW",
"id_cat_padre":"0"
}
]
然后我将此字符串转换为类别列表
lsSubCategorias = JsonConvert.DeserializeObject<List<Categoria>>(json, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
我已经在代码中添加了痕迹,它就在它停止的那一行。
我使用 NuGet 安装了 Newtonsoft.Json,它出现在参考文献中。
我也只处理了一个类别对象而不是列表,但它也不起作用。 这不是可视化问题,因为我已经创建了类别对象并使用它们创建了按钮。
问题是它可以在 Unity Editor 中运行,但在我的 android 设备上不起作用
我的手机出现以下错误:
输入错误:System.PlatformNotSupportedException ToString错误():Error.ToString()
Unity3d il2cpp 目标(如移动设备)不支持来自 NuGet 的I Installed the Newtonsoft.Json using the NuGet and it appears in the references.
Newtonsoft.Json。使用资产商店的 Newtonsoft.Json 分支,例如 this one.
@DoctorPangloss 的回答 Newtonsoft.Json 在使用 IL2CPP 脚本后端构建时遇到了问题。这是因为 Newtonsoft.Json 没有任何完全支持 AOT 的可用版本。
有很多提供 Newtonsoft.Json 支持 AOT 的第三方解决方案。 ParentElement 的链接 JSON .NET 是一个很好的解决方案,但是该项目已经死了几年了,并且只提供了 Newtonsoft.Json 到版本 8.0.3。
我建议查看我的存储库,交付 Newtonsoft.Json 最高版本 12.0.3(在撰写本文时)并通过内置的 Unity 包管理器交付:https://github.com/jilleJr/Newtonsoft.Json-for-Unity#readme
要了解更多信息,请从 Newtonsoft.Json 的上下文中阅读我关于 What even is AOT? 的 post。