I created a C# library project. The project has this line in one class:
JsonConvert.SerializeObject(objectList);
I\'m getting error saying
right click on the project and select Manage NuGet Packages..
In that select Json.NET
and install
After installation,
use the following namespace
using Newtonsoft.Json;
then use the following to deserialize
JsonConvert.DeserializeObject
If you're using Linux and .NET Core, see this question, you'll want to use
dotnet add package Newtonsoft.Json
And then add
using Newtonsoft.Json;
to any classes needing that.
JsonConvert
is from the namespace Newtonsoft.Json
, not System.ServiceModel.Web
Use NuGet
to download the package
"Project" -> "Manage NuGet packages" -> "Search for "newtonsoft json". -> click "install".
Or if you're using dotnet Core,
add to your .csproj file
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
</ItemGroup>
And
dotnet restore
Tools -> NuGet Package Manager -> Package Manager Console
PM> Install-Package Newtonsoft.Json
Try this in C#. It works:
var jsonObject = JsonConvert.DeserializeObject(File.ReadAllText(MyFilePath));
Import below namespaces :
For JsonConvert: using Newtonsoft.Json;
For File : using System.IO;