我正在嘗試爲我正在編寫的API傳遞一個JSON字符串。這裏的JSON後的樣子:使用JSON2Csharp將JSON數組嵌套到C#類
{"AssociatedApplication":"Postman", "Key":"a274e012c52d4121bda7d1e7a7218cf5", "Subject":"Testing API", "Body":"Testing email API. Muffins.",
"EmailAddresses":[
{"From":"[email protected]"},
{"To":"[email protected]"},
{"To":"[email protected]"},
{"Cc":"[email protected]"},
{"Bcc":"[email protected]"}
]
}
,我有我的課設置爲
[NotMapped]
class EmailTransmission
{
public string AssociatedApplication;
public string Key;
public string Subject;
public string Body;
public List<EmailAddress> EmailAddresses;
}
[NotMapped]
public class EmailAddress
{
public string From { get; set; }
public string To { get; set; }
public string Cc { get; set; }
public string Bcc { get; set; }
}
當我使用JsonConvert.DeserializeObject<List<EmailAddress>>(email["EmailAddresses"])
它不工作,我已經試過List<List<string>>
列表等向前。我應該使用什麼類型而不會獲得運行時類型聯編程序異常?
這就是它 - 感謝! – Dreamcasting
@Dreamcasting樂意幫忙! –