慕哥6287543
1) 如果您的 json 是一个对象,例如 MyUserpublic class MyUser{ public int Id { get; set; } public string Name { get; set; } public string Description { get; set; }}你的json是{ "Id": 1, "Name": "Andrew", "Description": "Software Engineer"}然后您可以使用以下代码轻松反序列化MyUser user = JsonConvert.DeserializeObject<MyUser>(data);上面代码中的“数据”是你的json文件数据。2) 如果您的 json 是一个对象数组,例如 MyUser 数组。{ "Users": [ { "Id": 1, "Name": "Andrew", "Description": "Software Engineer"}, { "Id": 2, "Name": "Eddy", "Description": "Software Developer"}, { "Id": 3, "Name": "Matthew", "Description": "Web Developer"} ]}那么你需要一个 IEnumerable 类型属性 MyUser 的视图模型来反序列化public class MyUserVM{ public IEnumerable<MyUser> Users { get; set; }}然后你需要使用上面的视图模型反序列化MyUserVM users = JsonConvert.DeserializeObject<MyUserVM>(data);上面代码中的“数据”是你的json文件数据。Q) 为什么这里需要视图模型?A) 因为 json 是一种基于文本的键值格式数据,您需要一个键才能在 JsonConvert 类中读取它。编辑:你请改变你的json键,如下所示{ "name": "xx", "place": { "native": "aa", "school": "ee", "college": "dd" }, "dob": "ss", "ids": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120 ], "mark": [ { "tenthmark": "345", "twelthmark": "1100" }, { "Diploma": "G", "DiplomaPG": "R" }, { "Ug": "D", "PG": "E" } ]}并使用我为您创建的以下视图模型public class Place{ public string native { get; set; } public string school { get; set; } public string college { get; set; }}public class Mark{ public string tenthmark { get; set; } public string twelthmark { get; set; } public string Diploma { get; set; } public string DiplomaPG { get; set; } public string Ug { get; set; } public string PG { get; set; }}public class RootObject{ public string name { get; set; } public Place place { get; set; } public string dob { get; set; } public List<int> ids { get; set; } public List<Mark> mark { get; set; }}然后使用反序列化RootObject rootObject = JsonConvert.DeserializeObject<RootObject>(data);