JSON序列将继承类型 [英] JSON deserialization to inherited types

查看:178
本文介绍了JSON序列将继承类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的数据库中的数据表,我储存的各种设置。由于他们是任何类型的(即使是复杂的对象图)的,我决定来存储它们的值序列化的JSON字符串。

I have a data table in my database where I store various settings. Since they are of any type (even complex object graphs) I decided to store their values as serialized JSON strings.

让我们说,我序列化一个名单,其中,ItemBase> 。序列化字符串看起来就好了。但问题是,列表项是指从 ItemBase 继承的各类(可能还有是抽象的,我也不在乎)的。

Let's say that I serialized a List<ItemBase>. Serialized string looks just fine. But the problem is that list items are of various types that are inherited from ItemBase (which may as well be abstract for what I care).

这(德)序列化类/库我应该用,所以我的JSON字符串将被正确地反序列化到正确的对象实例。

Which (de)serialization class/library should I use so my JSON strings will be correctly deserialized to correct object instances.

推荐答案

json.net 有能力<一HREF =htt​​p://james.newtonking.com/projects/json/help/$p$pserveObjectReferences.html> preserve引用

和它支持的<一个href="http://james.newtonking.com/archive/2010/08/13/json-net-3-5-release-8-3-5-final.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+jamesnewtonking+%28James+Newton-King%29">storing类型

这篇关于JSON序列将继承类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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