C # parses JSON data in the form of arrays

Source: Internet
Author: User

In the study of the problem of parsing JSON data, the internet also searched a lot of information to be realized, recorded so as to flip through.

1. Download the Open source class library Newtonsoft.json (http://json.codeplex.com/can also be downloaded here)

2. VS Add DLL Reference
(1). I placed the. dll file under the Bin/debug file
(2). C # project name, right-click Add, click to browse, select the file location of the. dll, OK
(3). Add Reference: Using Newtonsoft.json;

3. Generate a C # entity class corresponding to a JSON string
JSON-generated Entity class tool: Http://tool.chinaz.com/tools/json2entity.aspx (note: When generating the entity class for JSON format data, each pair of parameters is separated by commas)

Data to parse in JSON format:

[    {         "ItemNumber":"022" ,        "ItemName":"Cap"     },    {         "ItemNumber":"023",        "ItemName":"Golve"     }]

Auto-generated entity classes:

classitem{/// <summary>    ///numbering/// </summary>     Public stringItemNumber {Get;Set; } /// <summary>    ///name/// </summary>     Public stringItemName {Get;Set; }}classitemlist{/// <summary>    ///Item List/// </summary>     PublicList<item> Item {Get;Set; }}

4. Parsing JSON data

string " [{' ItemNumber ': ' 022 ', ' itemname ': ' Cap '},{' itemnumber ': ' 023 ', ' itemname ': ' Golve '}] " // to have [] jsonconvert.deserializeobject<itemlist> (jsontext); // deserializes a JSON string to get an object foreach inch Itemlist.item) {    Console.WriteLine (item.itemnumber);    Console.WriteLine (item.itemname);}

Reference:

77647625

Https://www.cnblogs.com/zxx193/p/3664562.html

C # parses JSON data in the form of arrays

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.