How to import JsonConvert into a C # application?

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?

+43
Sep 13 '13 at 10:59 on
source share
6 answers

JsonConvert - from the Newtonsoft.Json namespace, not System.ServiceModel.Web

Use NuGet to download package

Project → NuGet Package Management → Search for newtonsoft json. → click install.

+87
Sep 13 '13 at 10:59 on
source share

right click on the project and select Manage NuGet Packages.. In this select Json.NET and install

After installation

use the following namespace

 using Newtonsoft.Json; 

then for deserialization

use the following:
 JsonConvert.DeserializeObject 
+23
Aug 26 '14 at 6:44
source share

Install it using NuGet:

 Install-Package Newtonsoft.Json 


Submitting this as an answer.

+11
Feb 11 '16 at 17:14
source share

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 
0
Aug 31 '17 at 7:38
source share

Linux

If you are using Linux and .NET Core, see this question , you will want to use

 dotnet add package Newtonsoft.Json 

And then add

 using Newtonsoft.Json; 

for any classes that need it.

0
Dec 29 '17 at 7:55
source share

Tools -> NuGet Package Manager -> Package Manager Console

 PM> Install-Package Newtonsoft.Json 
-one
Oct. 23 '17 at 17:34 on
source share



All Articles