Problem
I’m getting the below error when I trying to add the NewtonsoftJson package to asp.net web API core 3.1 project
Package restore failed. Rolling back package changes
Solution
It was an issue while installing the NewtonsoftJson package to my asp.net core API 3.1v project, so I tried to clear the cache of the All NuGet packages and restarted the visual studio.

Try to install old version package, for my .net core 3.1 project i have isntalled newtonsoftjson version 3.1.0. as shown in the below image.

After that make sure that you have installed NewtonsoftJson 3.1.10 version installed in your project. if your project version is low then same low version NuGet packages version.

After I cleared the cache, I was able to download the NuGet package API into my asp.net core project.
Summary
Clear of NuGet packages cache can also solve the problems when we are failing to install the new NuGet packages to our asp.net core projects.