To become a master of the ocean, you must know the real name of every drop of water in the sea.
At the beginning, I just wanted to find a method to convert the JSON array. The result was displayed in the dig command on MSDN.
A lot of terms are inevitable during the search process: WCF => DataContract => DataMember => DataContractJsonSerializer, and then the namespace is continuously introduced.
This experience immediately reminds me of the words referenced above that exist in the Wizard of a novel. The static language is a little crazy, so it is possible to start working without stopping preparation.
ComparisonSeveral common JSON parsing methods under. NET Main Category Namespace Restrictions Built-in LINQ support DataContractJsonSerializer System. runtime. serialization. json generic No. JavaScriptSerializer System. web. script. serialization can only use no JsonArray, JsonObject, and JsonValue System in the Web environment. json can only be used in Silverlight as JsonConvert, JArray, JObject, JValue, and JProperty Newtonsoft. json is used to prepare data.
Entity class:
[DataContract]
public class Person
{
[DataMember(Order = 0, IsRequired = true)]
public string Name { get; set; }
[DataMember(Order = 1)]
public int Age { get; set; }
[DataMember(Order = 2)]
public bool Alive { get; set; }
[DataMember(Order = 3)]
public string[] FavoriteFilms { get; set; }
[DataMember(Order = 4)]
public Person Child { get; set; }
}
Definition:
Action<object> log = o => Console.WriteLine(o);
Func<int, int, int> add = (x, y) => x + y;
var p1 = new Person {
Age = 12,
Alive = true,
Name = "lj",
FavoriteFilms = new[] { "Up", "Avatar" }
};
var p2 =&