c# json package

  • 84
  • 0

c# json package

JSON NET is powerful. I record 2 ways of its usage here:

1. Basic Convert or Revoncert C# Class or List, IEnumerable, etc to JSON:

https://www.newtonsoft.com/json/help/html/SerializingJSON.htm

2. Extremely elastically create JSON by JObject, this is incrediblly amazing, for variable json object pattern, you don't need to hard code each pattern as  class, and slowly give each property value, you can directly create it as JObject by LINQ or Anonymous Class !  :

https://www.newtonsoft.com/json/help/html/CreatingLINQtoJSON.htm

but the shortcoming of directly create, is it cannot be reuse, so if the format is used in many place, you could consider to hard code it as class.

 

Another great tutorial:

使用dynamic簡化Json.NET JObject操作