How to Serialize List to JSON (C#)

Do you need to serialize a list to JSON to deliver it to some kind of web service? Simply use Json.NET.
You might need to install Json package first. Use NuGet to find Newtonsoft.Json or use Package Manager and execute:
PM> Install-Package Newtonsoft.Json

Serialization done with oneliner:
using Newtonsoft.Json;
var json = JsonConvert.SerializeObject(aList);

No comments:

Post a Comment