我们的团队选择了Couchbase作为我们应用程序的缓存。我们在这个缓存中存储的是这样的对象
public class CatalogEntity
{
public int Id { get; set; }
public string Name { get; set; }
// this property gives us trouble
public Hashtable Attributes { get; set;}
}
在我们的代码中,从 CouchBase 缓存中检索对象后,我发现主要类型( Id
和 Name
)的属性已正确反序列化,但 Attributes
的 Hashtable
类型未反序列化并保持为 JSON。例如,如果我有类似的东西
var entity = new CatalogEntity();
entity.Attributes["foo"] = new Foo();
缓存中的对象将具有 Attributes["foo"]
属性作为 Foo
的 JSON 表示形式类(class)。
我想知道如何获得 Hashtable
类型正确序列化/反序列化?我是否应该将对象序列化为二进制文件并将二进制流存储在 CouchBase 中?
最佳答案
您是否有理由需要使用 Hashtable
?例如,您可以使用 Dictionary<string,string>
吗?相反?
我认为您看到的原因是 Json.NET 对哈希表进行序列化的最佳尝试(另请参阅 StackOverflow 上的这个问题:Serialize hashtable using Json.Net)。
关于c# - 使用 HashTable 属性序列化一个对象并存储在 CouchBase 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38210310/