反序列化为 IEnumerable<IEnumerable<CustomType>>

Deserialize to IEnumerable<IEnumerable<CustomType>>

任何人都可以帮助我如何将 json 反序列化为 IEnumerable<IEnumerable<CustomType>>

我有一个 JSON 对象,如下所示:

[
    [{"Role" : "RoleA"},{"Role" : "RoleB"}],
    [{"Role" : "RoleC"}],
    [{"Buyer" : "UserA"}]       
]

如何反序列化为 IEnumerable<IEnumerable<CustomType>>,其中 CustomType

public class CustomType
{
    public string Type { get; set; }
    public string Value { get; set; }

    public Dictionary<string, string> AsJsonProperty()
    {
        return new Dictionary<string, string>
        {
            {Type, Value}
        };
    }
}

您不能反序列化到接口。请记住,它们实际上只是 class 实施的合同。相反,您应该使用具体的 class,例如 List<>:

JsonConvert.DeserializeObject<List<List<CustomClaimData>>>(metaDat‌​a["ReadClaims"]);