【发布时间】:2019-10-12 09:41:18
【问题描述】:
我正在使用编辑器数据表并将数据从编辑器返回到控制器,并尝试从所谓的Dictionary<string,object> 中读取值。任何人都可以建议这是如何完成的。我读到 Dictionary 需要进行 Json 反序列化,但不太确定它是如何完成的。我包括一张我试图阅读的价值观的图片。谢谢enter image description here
我在控制器中读取了通过 e.Values 返回的数据:
editor.PostCreate += (sender, e) => t = Task.Run(() => Add(intContTpe, lngContIdx, e.Values));
internal static void Add(int intContTpe, long lngContIdx, object objPCEAValues)
{
Dictionary<string, object> dicVoDaCDRFormats = new Dictionary<string, object>();
if (!dicPCEAValues.ContainsKey("CustomerVoiceCLICDRFormats.0"))
{
dicVoDaCDRFormats = ((Dictionary<string, object>)dicPCEAValues["CustomerVoiceCLICDRFormats"]);
PrintToOutput("", ((Dictionary<string, object>)dicPCEAValues["CustomerVoiceCLICDRFormats"])["0"]);
}
}
【问题讨论】:
-
您已经有一本包含所需值的字典。为什么要反序列化?如果您希望对象成为特定类型,只需转换它们即可。
-
foreach (KeyValuePair
items in dicVoDaCDRFormats) { PrintToOutput("", items.Value);如果我尝试从 dicVoDaCDRFormats 迭代键值对,我得到的不是图片中的值,而是“System.Collections.Generic.Dictionary`2[System.String,System.Object]”
标签: c# model-view-controller datatables