这是我的json,我需要访问出勤数组中每个对象下的值:
{"name":" ","course":"","attendance":[{"name":"INTERNATIONAL FINANCE","type":"Theory","conducted":"55","present":"50"},{"name":"INDIAN CONSTITUTION","conducted":"6","present":"6"}]}
这是我的代码:
public class Att { public class Attendance { public string name { get; set; } public string type { get; set; } public string conducted { get; set; } public string present { get; set; } } public Att(string json) { JObject jObject = JObject.Parse(json); JToken jUser = jObject; name = (string)jUser["name"]; course = (string)jUser["course"]; attender = jUser["attendance"].ToList<Attendance>; } public string name { get; set; } public string course { get; set; } public string email { get; set; } //public Array attend { get; set; } public List<Attendance> attender { get; set; } }
它是出席者= jUser [“出席率”] .ToList<出席率> ;;我遇到问题的一句话.它说,
Cannot convert method group ToList to non-delegate type. Did you intend to invoke this method?
我如何访问这些值?
解决方法
你有一个错字!
attendance vs attendence
这应该工作
attender = jUser["attendance"].ToObject<List<Attendance>>();
您可以在DotNetFiddle找到运行结果