I created a C # library project. The project has this line in one class:
JsonConvert.SerializeObject(objectList);
I get an error
The name JsonConvert does not exist in the current context.
To fix this, I added System.ServiceModel.Web.dll to the links, but no luck. How can I solve this error?
System.ServiceModel.Web.dll
JsonConvert - from the Newtonsoft.Json namespace, not System.ServiceModel.Web
JsonConvert
Newtonsoft.Json
System.ServiceModel.Web
Use NuGet to download package
NuGet
package
Project → NuGet Package Management → Search for newtonsoft json. → click install.
right click on the project and select Manage NuGet Packages.. In this select Json.NET and install
Manage NuGet Packages..
Json.NET
After installation
use the following namespace
using Newtonsoft.Json;
then for deserialization
JsonConvert.DeserializeObject
Install it using NuGet:
Install-Package Newtonsoft.Json
Submitting this as an answer.
Or if you use the dotnet core,
add to your .csproj file
<ItemGroup> <PackageReference Include="Newtonsoft.Json" Version="9.0.1" /> </ItemGroup>
AND
dotnet restore
If you are using Linux and .NET Core, see this question , you will want to use
dotnet add package Newtonsoft.Json
And then add
for any classes that need it.
Tools -> NuGet Package Manager -> Package Manager Console
PM> Install-Package Newtonsoft.Json