【问题标题】:Json.NET in Unity throwing 'The type or namespace `Newtonsoft` could not be found'Unity 中的 Json.NET 抛出“找不到类型或命名空间`Newtonsoft`”
【发布时间】:2016-06-28 18:56:41
【问题描述】:

我使用 nuget 将 Json.NET 安装到我的 Unity 项目中,但问题是当我启动它时会抛出 The type or namespace 'Newtonsoft' could not be found. Are you missing a using directive or an assembly reference
然而它在我的参考文献中,我有using Newtonsoft.Json;
我看过其他问题,但我找不到有效的答案。我正在使用 Unity 5 和最新版本的 Json.NET

【问题讨论】:

    标签: c# unity3d json.net


    【解决方案1】:

    1.在 Unity 中,将 Newtonsoft.Json.dll 文件放入 Assets/Plugins 文件夹中

    2。在 Visual Studio 中,突出显示 Solution Explorer 窗口中的 Analyzers

    3.转到Project-> Add Reference 并选择您的项目目录,然后选择Assets/Plugin。就是这样。

    可选

    在 Unity 5.3 中,Unity 添加了 native supportJson 序列化。您可以简单地使用它来转换为Json 并返回到class

    【讨论】:

    • 谢谢,这行得通。我为不尝试公平而感到愚蠢。再次感谢。
    • 我需要对我的 sln 中的每个项目进行这些更改(跳转到错误,为包含该文件的项目选择分析器,添加引用,跳转到下一个错误)并重新启动 Unity 以使其接受我的变化。
    • @idbrii 不应该发生。请注意,如果要使用 Newtonsoft,则必须使用 Unity forked Unity 版本。你可以得到那个here
    • @Programmer:不确定叉子是否仍然需要? Newtonsoft 11 在 Unity 5.6(针对桌面)中加载和构建/解析 json 时没有错误。
    • @idbrii 过去,在某些平台(如 iOS)上曾经出现过一些错误。此外,它需要 .NET 4.5。我认为这没有改变。
    【解决方案2】:

    转到Assets/JsonDotNet/Assemblies/AOT/Newtonsoft.Json,然后在检查器中检查适当的平台(iOSAndroidLumin)复选框,在Platform Settings 中选择适当的平台并点击Apply

    【讨论】:

      猜你喜欢
      • 2012-07-26
      • 1970-01-01
      • 2018-11-23
      • 1970-01-01
      • 1970-01-01
      • 2015-12-28
      • 2018-05-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多