使用数字作为属性名称反序列化JSON [英] Deserialize JSON with numbers as property names

查看:251
本文介绍了使用数字作为属性名称反序列化JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的JSON:

{"rows":
    {
        "1":{"rowNumber":1,"productID":"100"},
        "2":{"rowNumber":2,"productID":"101"},
        "3":{"rowNumber":3,"productID":"102"}
    }
}

我需要构建域模型.

例如:

class Row 
{
    public int rowNumber{get; set;}
    public string productID{get; set;}
}

根对象

class RootObject
{
   public ? ? rows {get; set;}
}

行属性必须是哪种类型?

What kind of type have to be rows propperty?

推荐答案

答案是

public Dictionary<int, Row> rows { get; set; }

并使用

JsonConvert.DeserializeObject<RootObject>(json);

用于反序列化. JsonConvert来自 Newtonsoft 库.

for deserialization. Where JsonConvert is from Newtonsoft library.

这篇关于使用数字作为属性名称反序列化JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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