[{ "name": "广州", "adcode": 440100},{ "name": "广州", "adcode": 440100}] 转成List C#
时间: 2023-12-01 16:02:24 浏览: 76
C#将DataTable转换成list的方法
以下是将给定的json字符串转换为List的C#代码:
```csharp
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
public class City
{
public string name { get; set; }
public int adcode { get; set; }
}
public class Program
{
public static void Main()
{
string json = @"[{""name"":""广州"",""adcode"":440100},{""name"":""广州"",""adcode"":440100}]";
List<City> cities = JsonConvert.DeserializeObject<List<City>>(json);
foreach (City city in cities)
{
Console.WriteLine(city.name + " " + city.adcode);
}
}
}
```
输出结果为:
```
广州 440100
广州 440100
```
阅读全文