C # several methods for parsing JSON

Source: Internet
Author: User

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<intintint> add = (x, y) => x + y; 
 
var p1 = new Person { 
    Age = 12, 
    Alive = true
    Name = "lj", 
    FavoriteFilms = new[] { "Up", "Avatar" } 
}; 
var p2 =&

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.