c# - 如何将 JSON 数组转换为 List<>?

标签 c# json windows-phone

这是我的 json,我需要访问出勤数组中每个对象下的值:

{"name":" ","course":"","attendance":[{"name":"INTERNATIONAL FINANCE","type":"Theory","conducted":"55","present":"50"},{"name":"INDIAN CONSTITUTION","type":"Theory","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; }
}

它是attender = jUser["attendance"].ToList<Attendance>;我遇到问题的行。它说,

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 找到运行结果。

关于c# - 如何将 JSON 数组转换为 List<>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24350659/

相关文章:

c# - 另一个更大数组中的数组,包括使用 Linq 的重复项

c# - 加载 JSON 文件会出现序列化错误

scroll - Windows Phone - 避免滚动放置在滚动查看器内的 Web 浏览器控件

json - Play 2.3 隐式json转换导致空指针异常

json - 条件 Karate API 测试工具中的模糊匹配

android - 一个移动应用程序可以支持多个不同的 MDM 吗?

.net - 通用应用的主题资源

c# - 如何从云 Web 服务中访问文件?

c# - foreach 与 someList.ForEach(){}

c# - 将匿名类型转换为 IList