'Json.NET in Unity throwing 'The type or namespace `Newtonsoft` could not be found'
I used nuget to install Json.NET into my Unity project but the issue is when I launch it throws
The type or namespace 'Newtonsoft' could not be found. Are you missing a using directive or an assembly reference
Yet it is in my references and I have using Newtonsoft.Json;
I have looked at other questions but I could not an answer which worked. I am using Unity 5 and the latest version of Json.NET
Solution 1:[1]
1.In Unity, place the Newtonsoft.Json.dll
file into the Assets/Plugins
folder
2.In Visual Studio, highlight Analyzers
in the in Solution Explorer
window.
3.Go to Project
-> Add Reference
and choose your project directory followed by Assets/Plugin
. That's it.
Optional:
In Unity 5.3, Unity added native support of Json
serialization. You can simply use that to convert to Json
and back to class
.
Solution 2:[2]
Go to Assets/JsonDotNet/Assemblies/AOT/Newtonsoft.Json
then in Inspector check proper platform (iOS
, Android
or Lumin
) checkbox in General, select proper platform in Platform Settings
and hit Apply
.
Solution 3:[3]
The accepted answer will work, and only requires step 1 in current versions of Unity. However, there is a cleaner solution:
Open the
Packages
folder in your system's file browseredit
manifest.json
In the dependencies section, add this line:
"com.unity.nuget.newtonsoft-json": "2.0.0"
(optional) go to the Package Manager window and update to the current version
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Programmer |
Solution 2 | Boken |
Solution 3 | phoff |