将数据字典转换为对象c# [英] cast data dictionary to object c#
本文介绍了将数据字典转换为对象c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
我有变量列表字典< string,string>其中包含对象列表作为键值对(字典项作为对象属性)
ex _ListDataDict [0] = {{lstName,pla},{Age},20如何将数据字典列表转换为对象列表人员
列表<字典<字符串,字符串>> _ListDataDict
// class属性
class person {
string lstName;
string年龄;
}
解决方案
您不能直接将Dictionary转换为任何类型的对象。
这就是你需要做的事情
Person p = JsonConvert.DeserializeObject< person>(_ ListDataDict [0]);< / person>
Json.Convert
可在Newtonsoft.Json dll中找到,可以从网上下载。
Dear All,
i have variable List Dictionary<string,string> which contain list of object as key value pairs (dictionary items as object attributes )
ex _ListDataDict[0]={{"lstName","pla"},{"Age"},"20"} how can i casting data-dictionary list to list of object Person
List<Dictionary<string, string>> _ListDataDict //class Attributes class person { string lstName; string Age; }
解决方案
You cannot cast a Dictionary into an object of any type directly.
This is what you will need to do
Person p = JsonConvert.DeserializeObject<person>(_ListDataDict[0]);</person>
Json.Convert
is available in Newtonsoft.Json dll which can be downloaded from the web.
这篇关于将数据字典转换为对象c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文