json反序列化为C#
问题描述:
对我的Web请求的响应如下(不在我的控制范围内):
The response to my web request coming as the following (not under my control):
{
"nasdaq_imbalance":
{
"name": "nasdaq_imbalance",
"group": "Market Data",
"description": null
},
"DXOpen IM":
{
"name": "DXOpen IM",
"group": "Daily",
"description": null
},
"Float Shares":
{
"name": "Float Shares",
"group": "Daily",
"description": null
},
}
不知何故,我需要将其反序列化为包含对象列表的C#对象...基本上,我需要像这样的对象列表:
Somehow, I need to deserialize that into C# object that contains a list of objects... Basically I need a list of objects like that:
public class Dataset {
public string name { get; set; }
public string group { get; set; }
public string description { get; set; }
}
答
如果使用的是Json.NET,则可以使用 JsonConvert.DeserializeObject< Dictionary< string,Dataset>>(json)
字典的键将是 nasdaq_imbalance
, DXOpen IM
, Float Shares
If you are using Json.NET, you can use JsonConvert.DeserializeObject<Dictionary<string, Dataset>>(json)
and the keys of the dictionary will be nasdaq_imbalance
, DXOpen IM
, Float Shares