当用DataContractJsonSerializer类序列化对象为Json时,发现序列化后的json对象,每个属性都带有k__BackingField后缀,像这样:
解决办法:为要被序列化的类打上相应标记,像下面这样:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[Serializable] [DataContract] public
class
Person
{ private
string
_name;
[DataMember]
public
string
Name
{
get
{ return
_name; }
set
{ _name = value; }
}
} |
参考:http://forums.asp.net/t/1903020.aspx/1