[英]How do I extract value from object {System.Collections.Generic.KeyValuePair<string, object>?
I have the following object: 我有以下对象:
object {System.Collections.Generic.KeyValuePair<string, object>}
Key is "ipAddresses" string Value is object[]
where [0] in this array is an object[string] that I would like to extract. 关键是“ ipAddresses”字符串值是
object[]
,其中此数组中的[0]是我要提取的object [string]。 (it's an IP address) (这是一个IP地址)
I tried the following code among other things with no success: 我尝试了以下代码,但没有成功:
object.GetType().Getproperty("ipAddresses")
object.GetType().GetField("ipAddresses")
Note that the object type is: (from watch) 请注意,对象类型为:(来自监视)
value 值
{[ipAddresses,System.Object[]]} {[ipAddresses,System.Object的[]]}
Type 类型
object{System.Collections.Generic.KeyValuePair} 对象{System.Collections.Generic.KeyValuePair}
I'd like to save value[0]
from the KeyValuePair to a string. 我想将KeyValuePair中的
value[0]
保存到字符串中。 Any help would be highly appreciated :) 任何帮助将不胜感激:)
object obj; //get key value pair from somewhere
object ips = ((KeyValuePair<string, object>)obj).Value;
string ip = ((object[])ips)[0].ToString();
string ipAddress = object["ipAddresses"][0];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.