Unity中的Json.NET投掷'类型或名称空间`Newtonsoft`无法找到'

bwf*_*shy 5 c# json.net unity-game-engine

我使用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

Led*_*ine 11

去:

Window -> Package Manager
Run Code Online (Sandbox Code Playgroud)

单击加号按钮

Add Package from GIT URL > com.unity.nuget.newtonsoft-json
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在此输入图像描述


Pro*_*mer 9

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

2.在Visual Studio中,AnalyzersSolution Explorer窗口中突出显示.

3.转到Project- > Add Reference并选择项目目录,然后选择Assets/Plugin.而已.

可选:

在Unity 5.3中,Unity添加了序列化的本机支持Json.您可以简单地使用它转换为Json和返回class.

  • 谢谢,这有效。我因为没有尝试做到公平而感到愚蠢。再次感谢。 (2认同)

小智 8

接受的答案是可行的,并且在当前版本的 Unity 中只需要执行步骤 1。然而,有一个更干净的解决方案:

  1. Packages在系统的文件浏览器中打开该文件夹

  2. 编辑manifest.json

  3. 在依赖项部分中,添加以下行:

    “com.unity.nuget.newtonsoft-json”:“2.0.0”

  4. (可选)转到包管理器窗口并更新到当前版本