This article is a mirror article of machine translation, please click here to jump to the original article.

View: 22752|Reply: 1

[Source] c# parse json strings into List collections

[Copy link]
Posted on 9/3/2015 11:52:25 PM | | | |


The json data we get is as follows:
[{ "sheng": "140000", "shi": "140300", "qu": "140321" },{ "sheng": "210000", "shi": "210400", "qu": "210411" },{ "sheng": "530000", "shi": "530400", "qu": "530421" }]
We want to convert to a List collection, first define a class class:

  1. public class pl {
  2.             public int sheng { get; set; }
  3.             public int shi { get; set; }
  4.             public int qu { get; set; }
  5.         }
Copy code
Then use system.Web.scrip{filter}t.Serialization; The following Javascrip{filter}tSerializer to parse the json data,

Instantiate: Javascrip{filter}tSerializer js = new Javascrip{filter}tSerializer();

Convert to a List collection: List<pl> b = js. Deserialize<List<pl>>("[" + json + "]");




Previous:Regarding the workaround for the Linq field to be null and not showing data
Next:Half of China's Internet, how good is Alibaba?
Posted on 9/4/2015 9:41:18 AM |
In the past, it was used to add references to the Newtonsoft.Json dynamic connection library to deserialize json, but Microsoft doesn't have its own deserialization function, so why use a third-party one?
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com