[英]Column Name of dynamic object
How can I get the header (columns Name) of a dynamic List ?如何获取动态列表的标题(列名称)?
here is my code这是我的代码
var Participants = Newtonsoft.Json.JsonConvert.DeserializeObject<List<dynamic>>(obj.ToString());
and I need to get the name of all the column inside the var Participants
我需要获取 var
Participants
中所有列的名称
Any ideas ?有什么想法吗?
Use Newtonsoft.Json.Linq.JProperty
, take for example you have the following json object:使用
Newtonsoft.Json.Linq.JProperty
,例如您有以下 json 对象:
{ "summary" : { "123": {}, "456": {} } }
You want to deserialize to a list of the following:您想反序列化为以下列表:
class SomeClass {
public string ID {get;set;}
}
Your code would be:您的代码将是:
dynamic responseDynamic = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
List<SomeClass> someList = new List<SomeClass>();
foreach (var item in responseDynamic.summary)
{
string id = ((Newtonsoft.Json.Linq.JProperty)item).Name;
someList.Add(new SomeClass(){ID = id});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.