属性无法反序列化,因为成员的“属性”不是公共的

时间:2013-03-26 06:39:55

标签: c# .net-4.5

  

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

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

public class AccountData
{

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

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

}

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

1 个答案:

答案 0 :(得分: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

相关问题