trying to add a directive for NewtonSoft.Json to my newly made C# file. It's in .Net V6 so the file is stripped down, how do I import the Json library without adding the old framework with the brackets and class definition and everything?
I tried this in the .cs file but it doesn't work:
using NewtonSoft.Json;
Console.WriteLine(JsonConvert.SerializeObject(args));
I also tried this in the .csproj file and it also doesn't work:
<ItemGroup>
<Using Include="NewtonSoft.Json"/>
</ItemGroup>
Any help is appreciated, I've only been trying this for an evening and I'm already stumped!
CodePudding user response:
- Open your solution explorer tab,
- search for the Solution, right click it,
- choose Manage Nuget Packages for solution,
- it will open the installed tab of the NuGet package manager,
- go to the leftmost tab Browse, search for Newtonsoft.Json and select the project you wish to install it.
You made it.
CodePudding user response:
You have wrong namespace change it to Newtonsoft.Json
(after installing Newtonsoft.Json
nuget package)
using Newtonsoft.Json;
Console.WriteLine(JsonConvert.SerializeObject(args));
Or
<ItemGroup>
<Using Include="Newtonsoft.Json"/>
</ItemGroup>
P.S.
Probably you can consider switching to System.Text.Json
which is a modern framework-provided json handling library.