VS quickly generates entities corresponding to the JSON data format, vsjson data entities

Source: Internet
Author: User

VS quickly generates entities corresponding to the JSON data format, vsjson data entities

There is a fixed Json data format. Are you still typing the corresponding entity manually? A little low! Step into the question, this is a json string, first verify the JSON data format (http://www.bejson.com/) as follows:

{"Items_custom_get_response": {"items": {"item": [{"num_iid": 1, "product_id": 0, "skus": [{"created ": null, "modified": null, "outer_id": null, "price": null, "properties": null, "properties_name": "black", "quantity ": "2", "sku_id": null}]}

If you need to use it, you must deserialize it and serialize it into an object. The structure is as follows (in general, you will write it by hand, except for the gods ):

public class Rootobject        {            public Items_Custom_Get_Response items_custom_get_response { get; set; }        }         public class Items_Custom_Get_Response        {            public Items items { get; set; }        }         public class Items        {            public List<Item> item { get; set; }        }         public class Item        {            public int num_iid { get; set; }            public int product_id { get; set; }            public List<Sku> skus { get; set; }        }         public class Sku        {            public object created { get; set; }            public object modified { get; set; }            public object outer_id { get; set; }            public object price { get; set; }            public object properties { get; set; }            public string properties_name { get; set; }            public string quantity { get; set; }            public object sku_id { get; set; }        }

Do you think you are blind when writing this ??

The main user recommended a quick generation method, using VS2013 or 2015, as if VS2012 is not supported! How can we quickly generate corresponding entities? Copy the json string and paste the JSON string as a class. Then, the following file is generated in the class file:
public class Rootobject        {            public Items_Custom_Get_Response items_custom_get_response { get; set; }        }         public class Items_Custom_Get_Response        {            public Items items { get; set; }        }         public class Items        {            public Item[] item { get; set; }        }         public class Item        {            public int num_iid { get; set; }            public int product_id { get; set; }            public Sku[] skus { get; set; }        }         public class Sku        {            public object created { get; set; }            public object modified { get; set; }            public object outer_id { get; set; }            public object price { get; set; }            public object properties { get; set; }            public string properties_name { get; set; }            public string quantity { get; set; }            public object sku_id { get; set; }        }

It may be a little different from what you define. What is the difference between the object array and the generic list?

Arrays have many advantages. For example, arrays are stored continuously in the memory, so their indexing speed is very fast, and the assignment and modification of elements are also very simple; ArrayList is.. Net Framework provides a dedicated class for data storage and retrieval. It is a namespace System. A part of Collections. Its size is dynamically expanded and reduced according to the data stored in it. Therefore, we do not need to specify the length of an ArrayList object when declaring it. ArrayList inherits the IList interface, so it can easily add, insert, and remove data. It is precisely because ArrayList has the disadvantages of unsafe type and packing and unboxing, so the concept of generics emerged after C #2.0. The List class is the generic equivalent class of the ArrayList class. Most of its usage is similar to that of ArrayList, because the List class also inherits the IList interface. The most important difference is that when declaring a List set, we also need to declare the object type of data in the List set for it. The powerful functions of 12, 13, 15, and VS2015 are still under exploration ..... Source: http://www.cnblogs.com/viaiu/p/5007644.html

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.