简体   繁体   English

从System.Collections.Generic.Dictionary`2 [System.Object,System.Object]中读取数据

[英]Read Data From System.Collections.Generic.Dictionary`2[System.Object,System.Object]

I'm struggling to read data out of an IDictionary and would really appreciate some help. 我正在努力从IDictionary中读取数据,并希望得到一些帮助。 I've pulled out other data I need when it was just an object array, but I've got a KeyValuePair to deal with now. 当它只是一个对象数组时,我已经取出了我需要的其他数据,但是现在有一个KeyValuePair可以处理。 When I try and cast it as a KeyValuePair, I get an InvalidCastException so I did this to try and find the type: 当我尝试将其强制转换为KeyValuePair时,我收到了InvalidCastException,因此我这样做是为了尝试找到类型:

var test = plist["CFBundleIcons"];
MessageBox.Show(test.GetType().ToString());

Which returned System.Collections.Generic.Dictionary`2[System.Object,System.Object] . 哪个返回System.Collections.Generic.Dictionary`2 [System.Object,System.Object] My first question is what does the 2 mean? 我的第一个问题是2是什么意思? I've used dictionaries in the past and have never seen this before. 我过去使用过字典,但从未见过。

If it helps understand my main problem further, I've attached a screenshot of the locals view below - I'm trying to read the icon names. 如果它有助于进一步了解我的主要问题,请在下面附上本地视图的屏幕截图-我正在尝试阅读图标名称。 Thanks in advance. 提前致谢。

当地人观点

This is how the CLR encodes generic type names. 这就是CLR编码通用类型名称的方式。 `2 indicates the number of type parameters in the type. `2表示类型中类型参数的数量。

In C# terms, this is Dictionary<object, object> . 用C#术语来说,这是Dictionary<object, object>

It's just how .NET encodes a name of a generic type with two type parameters. 这就是.NET用两个类型参数编码通用类型名称的方式。 plist["CFBundleIcons"] is a Dictionary<object, object> . plist["CFBundleIcons"]Dictionary<object, object> So instead of casting it to KeyValuePair , you should cast it to the correct type. 因此,与其将其转换为KeyValuePairKeyValuePair将其转换为正确的类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase 数据库错误:System.Collections.Generic.Dictionary`2[System.String,System.Object] - Firebase Database Error: System.Collections.Generic.Dictionary`2[System.String,System.Object] Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]' - Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]' 从system.object上载到通用对象 - Upcasting to a generic object from system.object 序列化系统对象 - Serialization system.object 返回System.Object - Returns System.Object 无法将类型字符串隐式转换为System.Collections.Generic.Dictionary <string,System.Collections.Generic.Dictionary><string,object> &gt; - Cannot implicitly convert type string to System.Collections.Generic.Dictionary<string,System.Collections.Generic.Dictionary><string,object>> 无法将 System.Collections.Generic.List[System.Object] 类型的对象转换为 System.Collections.Generic.IList[ShortCodeList] - Unable to cast object of type System.Collections.Generic.List[System.Object] to type System.Collections.Generic.IList[ShortCodeList] 无法将类型为“System.Collections.Generic.List`1[System.Object]”的 object 转换为类型“System.Collections.Generic.List`1” - Unable to cast object of type 'System.Collections.Generic.List`1[System.Object]' to type 'System.Collections.Generic.List`1[customType] 如何访问System.Object中的数据? - How to access data in System.Object? 列表内的列表不打印元素,而是显示System.Collections.Generic.List`1 [System.Object] - List inside list does not print elements, instead shows System.Collections.Generic.List`1[System.Object]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM