简体   繁体   English

如何从对象{System.Collections.Generic.KeyValuePair中提取值 <string, object> ?

[英]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.

相关问题 无法将类型“ Newtonsoft.Json.Linq.JProperty”转换为“ System.Collections.Generic.KeyValuePair” <string,object> “ - Cannot convert type 'Newtonsoft.Json.Linq.JProperty' to 'System.Collections.Generic.KeyValuePair<string,object>' “System.Collections.Generic.KeyValuePair <string,object> &#39;不包含&#39;工作&#39;的定义 - 'System.Collections.Generic.KeyValuePair<string,object>' does not contain a definition for 'work' 无法从 'System.Collections.Generic.Queue 转换<system.collections.generic.keyvaluepair<potioncraft.potionrecipe.ingredient, uint> &gt;' </system.collections.generic.keyvaluepair<potioncraft.potionrecipe.ingredient,> - cannot convert from 'System.Collections.Generic.Queue<System.Collections.Generic.KeyValuePair<PotionCraft.PotionRecipe.Ingredient, uint>>' 无法转换类型&#39;System.Collections.Generic.KeyValuePair <int, dynamic> &#39;到&#39;System.Collections.Generic.Dictionary <int, dynamic> - Cannot convert type 'System.Collections.Generic.KeyValuePair<int, dynamic>' to 'System.Collections.Generic.Dictionary<int, dynamic> 将对象转换为具有“通用值”的 KeyValuePair? - Cast object to KeyValuePair with "generic value"? 如何从 System.Object 值中提取数组? - How do you extract an array from a System.Object value? 如何从 c# 中的“System.Collections.Generic.List`1[Microsoft.Online.Administration.UserLicense]”object 解析或提取数据 - How to parse or extract data from “System.Collections.Generic.List`1[Microsoft.Online.Administration.UserLicense]” object in c# C#-如何转换KeyValuePair <string,object> 到KeyValuePair <object,object> ? - C# - How can I cast KeyValuePair<string,object> to KeyValuePair<object,object>? 参数类型&#39;string&#39;不能分配给参数类型&#39;System.Collection.Generic.KeyValuePair <string,object> “ - Argument type 'string' is not assignable to parameter type 'System.Collection.Generic.KeyValuePair<string,object>' 获取 System.Collections.Generic.List1[System.Collections.Generic.KeyValuePair2[System.Int32,System.String]] 而不是字符串 - getting System.Collections.Generic.List1[System.Collections.Generic.KeyValuePair2[System.Int32,System.String]] instead of string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM