作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我坚持使用 OrmLite 的 POCO 对象中,我具有以下属性:
....
public Dictionary<string, object> CustomData { get; set; }
...
这个属性充满了数据,比如:
customData.Add("_GooglePassword", "blabla"); // this is a String
customData.Add("_ServerPort", 8093); // this is an Int32
// etc...
它以JSV的形式保存在数据库中,像这样:
{_GooglePassword:blabla,_ServerPort:8093}
当我反序列化它,返回到 C# 中的字典时,问题就来了,然后它将所有内容都作为字符串放回,正如 VS 中的这个异常所示:
因此,我没有将它返回到类中定义的 Int32,而是得到了字符串,这会带来问题。我很确定使用普通 JSON 和 DataContract 方法不会有这个问题,因为我在其他部分使用 JSON。
我是不是漏掉了什么?
谢谢 =)
最佳答案
为什么 DTO 中的继承不是一个好主意的一些有趣观点 from ss author和 here .
如果您的设置可以在配置文件中拆分,我建议您在接口(interface)/类中拆分每个属性集群,并将它们存储在单独的强类型属性中。
根据您的上下文,如果您只是存储信息而不是处理这些设置或将业务规则应用于这些设置,您可能会在属性中收到动态 json 并将其存储为字符串。这样您就不会仅仅为了存储目的而创 build 置类。
关于c# - ServiceStack 和 JSV : When I serialize a Dictionary<string, 对象 > 'object' 的类型在反序列化时丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20314481/
我是一名优秀的程序员,十分优秀!