Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Newtonsoft JSON package missing after moving project?

Discussion in 'Scripting' started by WavyRancheros, Apr 25, 2022.

  1. WavyRancheros

    WavyRancheros

    Joined:
    Feb 5, 2013
    Posts:
    176
    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?
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,945
  3. WavyRancheros

    WavyRancheros

    Joined:
    Feb 5, 2013
    Posts:
    176
    How can I add it?

    I can't find it in the package manager.
     

    Attached Files:

    MaxLohMusic and RiverExplorer like this.
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,945
    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 :)
     
  5. WavyRancheros

    WavyRancheros

    Joined:
    Feb 5, 2013
    Posts:
    176
    Thank you!
     
    MadeFromPolygons likes this.
  6. jeancallisti

    jeancallisti

    Joined:
    Oct 27, 2017
    Posts:
    8
    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:
    - Click on the "+" button. Select "Add package from git url..."
    - Now I'm looking for the url. I open https://docs.unity3d.com/Packages/com.unity.nuget.newtonsoft-json@3.0/manual/index.html . There, there's no link to the actual package. Only a link to the original Newtonsoft project repo, from which Unity forked. I try anyways: I use "https://github.com/JamesNK/Newtonsoft.Json.git" as a url. -> Unsurprisingly, Unity says that there's no package at that address.

    - I try again with url "https://www.nuget.org/api/v2/package/Newtonsoft.Json/13.0.3" from which I can download the nupkg file manually. Unity still rejects that url.

    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.
     
  7. jeancallisti

    jeancallisti

    Joined:
    Oct 27, 2017
    Posts:
    8
    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 :

    Code (CSharp):
    1. using Newtonsoft.Json;
    Unity rebuilds. Success.
     
  8. BrighturaStudios

    BrighturaStudios

    Joined:
    Nov 29, 2017
    Posts:
    5
    Thanks for this response! You're awesome.