Not sure where to put this.
I moved my project folder from one laptop to another.
Now I am getting errors that the Newtonsoft namespace could not be found.
I did not have any Newtonsoft folders in my project, so I guess it must have been in the packages?
But I tried to re-add Newtonsoft JSON as a package, but I can’t find it in the package manager?
Can anyone help?
How can I add it?
I can’t find it in the package manager.
2 Likes
You can add it via package manager using “com.unity.nuget.newtonsoft-json@3.0” or “com.unity.nuget.newtonsoft-json”, if unsure how to do that I suggest reading up on the different ways to add packages to package manager:
https://docs.unity3d.com/Manual/upm-ui-quick.html
Good luck
16 Likes
Forgive me, I don’t understand what any of that means. I’m fairly new to Unity.
What I tried:
1. With Visual Studio
- Opened the Unity solution (.sln file) in Visual Studio
- Opened the Package Manager in Visual Studio
- Added Newtonsoft.Json.
=> When I rebuild the solution in VS, no errors
=> Then, when I rebuild in Unity, it seems to ignore the package.
Failure.
2. With Unity’s Package Manager, by searching
(I’m using Unity 2021.3.29f1)
- Open unity’s Package Manager (Window → Package Manager)
- It starts with the dropdown set to “Packages: In Project”. I type “json” in the search bar → no result
- I change the dropdown to “Packages: Unity registry”. I type “json” in the search bar. → no results
- I change to “Packages: Built-in”. I type “json” in the search → I find “JSONSerialize”. that’s no good because that’s a different Json utility meant for Unity classes, not Newtonsoft.
2. With Unity’s Package Manager, by entering package name explicitly
- Still in Unity’s Package Manager
Attempt #1:
- Click on the “+” button. Select “Update package by name…”
- Enter “com.unity.nuget.newtonsoft-json@3.0” → Error in the unity console “Cannot find a version of package [com.unity.nuget.newtonsoft-json] compatible with this Unity version (2021.3.29f1)”
Attempt #2:
How do you add basic Json deserialization to Unity?
By the way I also tried System.Text.Json but since Unity targets an older version of .Net it’s not available.
I finally managed… I was so close!
- Open unity’s Package Manager (Window → Package Manager)
- Click on the “+” button. Select “Update package by name…”
- Enter com.unity.nuget.newtonsoft-json (just as MadeFromPolygons suggested… Tricked by my ADD again :-/ )
- The package gets installed
- Then in the C# file :
using Newtonsoft.Json;
Unity rebuilds. Success.
11 Likes
Thanks for this response! You’re awesome.
Thank you so much! U saved me
Please use the like button to show appreciation instead of necro posting.
Thread locked
1 Like