【问题标题】:Property cannot be deserialized because the member 'properties' is not public属性无法反序列化,因为成员“属性”不是公共的
【发布时间】:2013-03-26 06:39:55
【问题描述】:

无法反序列化数据协定类型“DTO.AccountData”,因为成员“properties”不是公共的。将成员设为公开将修复此错误。或者,您可以将其设为内部,并在程序集上使用 InternalsVisibleToAttribute 属性以启用内部成员的序列化 - 有关更多详细信息,请参阅文档。请注意,这样做有一定的安全隐患。

在我的班级中,所有成员变量都是公开的

public class AccountData
{

    public string mdn
    {
        get;
        set;
    }
    .....
    //other public varibales
    .....       

    public Dictionary<string, string> properties
    {
        get;
        set;
    }

}

更新
我尝试了 [DataContract] 和 [DataMember] 属性,但不起作用。

【问题讨论】:

  • 您是否重新编译了您的解决方案?
  • 从一开始就是public,是的,我清理并重新编译了项目
  • 您是否尝试使用 [DataContract] 属性标记类并使用 [DataMember] 标记其可序列化成员?
  • 是的,我也试过了..但不起作用..
  • Ï如果您尝试过,为什么您的样本没有全部属性! :D

标签: c# .net-4.5


【解决方案1】:

不幸的是,DataContractJsonSerializer 期望您的 json 数据为

  {"properties":[{"Key":"Name","Value":"Valorie"},{"Key":"Month","Value":"May"},{"Key":"Year","Value":"2013"}]}

我认为使用Json.NET 来解析json 是个好主意

更多信息你可以查看这个问题Parse dictionary from json windows phone

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多