C# - Convert Json To List Class

  • 2855
  • 0

C# - 將Json解析為物件的List

void Main()
{
	String RDJson = "[{\"roadid\":360,\"speed\":25},{\"roadid\":361,\"speed\":25}]";

	List<RoadInfo> roadInfos = JsonConvert.DeserializeObject<List<RoadInfo>>(RDJson);

	foreach (RoadInfo road in roadInfos)
	{
		road.Dump();
	}
}


public class RoadInfo
{
	public int roadid { get; set; }
	public int speed { get; set; }
}