C # parse JSON format in a form application

Source: Internet
Author: User
1. Reference The namespace system. Web. Script. serialization (you need to add. Net to reference system. Web. extension. dll). 2. Define a JSON-compliant tree structure object. For example, the JSON string format returned by the server is as follows :{
"Method": "getimagefullpathlist ",
"Imgpathlist ":{
"Imgpathlist ":[
"Http: // 10.9.34.207/imagedata/image/normalimage // 2012/02/18/05/02/-5-201202180258330682-0004916.jpg ",
"Http: // 10.9.34.207/imagedata/image/normalimage // 2012/02/18/01/02/-1-201202180258330682-0004916.jpg ",
"Http: // 10.9.34.207/imagedata/image/normalimage // 2012/02/18/03/02/-3-201202180258330682-0004916.jpg ",
"Http: // 10.9.34.207/imagedata/image/normalimage // 2012/02/18/0 A/02/-a-201202180258330682-0004916.jpg"
]
}
} The build object is as follows:

 public class ImageFullPathList
        {
            public string method;
            public innerImgPathList imgPathList;
        }
               
        public class innerImgPathList
        {
            public string[] imgPathList;
        }


3. Use the following statement to match the JSON string returned by the server to a custom struct. Jsonstr is the JSON string returned by the server.

 JavaScriptSerializer serializer = new JavaScriptSerializer();
ImageFullPathList json = serializer.Deserialize<ImageFullPathList>(jsonStr);


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.