C# 解析json中的key是数字的json

如果从服务端获取到的数据json中的key是数字,例如:

 

可以用以下的方式解析:

 public class TemplateModel
    {
        public int status { get; set; }
        public int error_code { get; set; }
        public string message { get; set; }
        public IDictionary<int, List<Template>> data { get; set; }
    }
    
    public class Template
    {
        public int type { get; set; }
        public string name { get; set; }
        public int super_type { get; set; }
        public string super_name { get; set; }
        public int group_type { get; set; }
        public string group_name { get; set; }
        public string unit { get; set; }
        public int priority { get; set; }
        public int is_default { get; set; }
        public int is_custom { get; set; }

    }

  再例如:

{
"ok": true,
"payment-methods": [
     {
     "id": "39sahf92ka9s02",
         "type": "ideal",
            "options": {
                "issuers": {
                    99: "Test Issuer"
                }
            }
        }
    ],
}
[JsonObject(MemberSerialization.OptIn)]
public class PaymentOptions
{
    [JsonProperty("ok")]
    public Boolean OK { get; set; }
    [JsonProperty("payment-methods")]
    public List<PaymentMethods> PaymentMethods { get; set; }
}
public class PaymentMethods
{
    [JsonProperty("id")]
    public string Id { get; set; }
    [JsonProperty("type")]
    public string Type { get; set; }
    [JsonProperty("options")]
    public Options Options { get; set; }
}
public class Options
{
    [JsonProperty("issuers")]
    public IDictionary<int, string> Issuers { get; set; }
}

 

posted @ 2022-03-09 16:32  清枫林  阅读(673)  评论(0编辑  收藏  举报