【问题标题】:MongoDB, json class & dictionary member serializingMongoDB、json 类和字典成员序列化
【发布时间】:2023-03-17 21:11:01
【问题描述】:

假设我有这样一门课:

class A
{
    Dictionary<string, string> Dict1 { get; set }
}

我希望它像这样被序列化为 Json:

"A" : {"strKey1" : "strVal1", "strKey2" : "strVal2"}

代替:

"A" : { "Dict1" : {"strKey1" : "strVal1", "strKey2" : "strVal2"}}

可以这么说,我想跳过生成“Dict1”键。

有可能吗?

另外,如何强制序列化“自定义”字典成员? 当我这样写我的课时:

class A : Dictionary<string, string> 

他们字典的键/值对没有被序列化...

提前谢谢你!

【问题讨论】:

    标签: json mongodb dictionary mongodb-.net-driver bson


    【解决方案1】:

    我自己搞定了——自定义序列化。

    【讨论】:

    • 愿意分享解决方案吗?
    猜你喜欢
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    • 2022-08-21
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    相关资源
    最近更新 更多