C# 在asp.net c中解析奇怪的Json#

C# 在asp.net c中解析奇怪的Json#,c#,asp.net,C#,Asp.net,我正在调用一个api,该api返回下面提到的json { "salarySlipItems" : { "\"0\"" : { "value" : "11000.00", "description" : "Worth Salary", "sort" : "1" }, "\"2\"" : { "value" : "500.00",

我正在调用一个api,该api返回下面提到的json

{
    "salarySlipItems" : {
        "\"0\"" : {
            "value" : "11000.00",
            "description" : "Worth Salary",
            "sort" : "1"
        },
        "\"2\"" : {
            "value" : "500.00",
            "description" : "Other Income",
            "sort" : "3"
        },
        "\"3\"" : {
            "value" : "1354.84",
            "description" : "General Allowance",
            "sort" : "4"
        },
        "\"4\"" : {
            "value" : "500.00",
            "description" : "Telephone Allowance",
            "sort" : "5"
        },
        "\"7\"" : {
            "value" : "-2000.00",
            "description" : "Other Deductions",
            "sort" : "8"
        }
    },
    "decimalDigits" : "2",
    "status" : "1"
}
有谁能指导我如何在c#asp.net中解析它?我所相信的是,工薪阶层是一个拥有所有属性的对象。什么是“0\\”2\等等?

\“2\”
在本例中是字典的键。它只是一个转义的
“2”
。在JSON响应中,出于某种原因,所有数字都显示为字符串

您可以使用
字典
反序列化此JSON对象:

public class Response
{
    public Dictionary<string, SlipItem> salarySlipItems { get; set; }
    public string decimalDigits { get; set; }
    public string status { get; set; }
}

public class SlipItem 
{
    public string value { get; set; }
    public string description { get; set; }
    public string sort { get; set; }
}
通过字典枚举:

foreach (var item in response) 
{
    Console.WriteLine("{0} has a description: {1}", item.Key, item.Value.description);
}
“2\”
在本例中是字典的一个键。它只是一个转义的
“2”
。在JSON响应中,出于某种原因,所有数字都显示为字符串

您可以使用
字典
反序列化此JSON对象:

public class Response
{
    public Dictionary<string, SlipItem> salarySlipItems { get; set; }
    public string decimalDigits { get; set; }
    public string status { get; set; }
}

public class SlipItem 
{
    public string value { get; set; }
    public string description { get; set; }
    public string sort { get; set; }
}
通过字典枚举:

foreach (var item in response) 
{
    Console.WriteLine("{0} has a description: {1}", item.Key, item.Value.description);
}

你可以参考,你可以参考
响应
还需要
小数位数
状态
@Rob是的,刚刚注意到:)更新。要扩展@Yeldar的答案,这只是一个普通的JSON对象,其属性恰好有一个数字作为名称。由于JSON对象本质上只是哈希表/字典,而且C不允许属性以数字开头,因此需要使用字典对其进行反序列化。
Response
还需要
小数位数
状态
@Rob yes,刚刚注意到:)已更新。要扩展@Yeldar的回答,这只是一个常见的JSON对象,其属性碰巧有一个数字作为其名称。由于JSON对象本质上只是哈希表/字典,而C#不允许属性以数字开头,因此需要使用字典对其进行反序列化。