在我使用syncfusion计划的ASP.NET(c#)应用程序中,我试图根据密钥从字典中获取值。
当我尝试这样做时,我收到此错误消息:
System.Collections.Generic.KeyNotFoundException:'字典中没有给定的密钥。
这行代码(我尝试获取密钥的值' Subject'并将其分配给变量sSubject
)会引发错误:
string sSubject = list["Subject"].ToString();
代码:
public Dictionary<string, object> Arguments { get; set; }
protected void Schedule1_ServerAppointmentEdited(object sender, Syncfusion.JavaScript.Web.ScheduleEventArgs e)
{
Arguments = e.Arguments["appointment"] as Dictionary<string, object>;
dynamic list = Arguments as Dictionary<string, object>;
string sSubject = list["Subject"].ToString();
}
如果我调试我的代码以查看字典中的内容,我确实看到了该键&#39;主题&#39;在场:
我做错了什么?我怎样才能获得价值&#39;测试主题&#39;来自关键&#39;主题&#39;?
项目:http://www.syncfusion.com/downloads/support/forum/119417/ze/ScheduleCRUDWithWebServices-728709208
谢谢
答案 0 :(得分:0)
您的词典位于列表中,即第二个元素。您应该按如下方式访问它:
string sSubject = list[1]["Subject"].ToString();
答案 1 :(得分:0)
这就是我最终检索键&#39; subject&#39;:
的价值Arguments = e.Arguments["appointment"] as Dictionary<string, object>;
//dynamic list = Arguments as Dictionary<string, object>;
System.Collections.ArrayList list2 = (System.Collections.ArrayList)Arguments["changed"];
Dictionary<string, object> dic = (Dictionary<string,object>)list2[0];
string sSubject2 = dic["Subject"].ToString();
答案 2 :(得分:0)