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!
You made it.
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>
PS
Probably you can consider switching to System.Text.Json
which is a modern framework-provided json handling library.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.