json反序列化为C# [英] json deserialization to C#

查看:71
本文介绍了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

这篇关于json反序列化为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆