C # Dynamic parsing of JSON object code

Source: Internet
Author: User

#region public class Jsonobject dynamic operation JSON object public class Jsonobject {//<summary>//parsing JSON string </summary> public static Jsonobject Parse (string json) {var js = new JavaScript            Serializer (); Object obj = js.            Deserializeobject (JSON);        return new Jsonobject () {Value = obj};        }///<summary>/////For object properties///</summary> public jsonobject this[string Key] {get {var dict = this.                Value as Dictionary<string, object>; if (dict! = null && dict.                ContainsKey (key)) {return new Jsonobject {Value = Dict[key]};            } return new Jsonobject ();        }}///<summary>///////</summary> Public jsonobject This[int Index]      {Get      {var array = this.                Value as object[]; if (array! = NULL && array.                Length > Index) {return new Jsonobject {Value = Array[index]};            } return new Jsonobject ();         }}///<summary>///To remove values as desired type///</summary> public T getvalue<t> ()        {return (t) Convert.changetype (Value, typeof (T));            }///<summary>///Remove the value of the string type///</summary> public string Text () {        Return convert.tostring (Value);            }///<summary>///value///</summary> public double number () {        Return convert.todouble (Value); }///<summary>///Take out integer//</summary> public int integer () {R        Eturn Convert.ToInt32 (Value); }//<summary>/Take out Boolean//</summary> public bool Boolean () {return Convert.toboolean (Value);            }//<summary>///value//</summary> public object value {            Get        Private set;            }///<summary>//If array length is returned///</summary> public int Length { get {var array = this.                Value as object[]; if (array! = NULL) {return array.                Length;            } return 0; }}} #endregion

  

C # Dynamic parsing of JSON object code

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.