DataContractJsonSerializer生成Ghost字符串到JSON密钥? [英] DataContractJsonSerializer generating Ghost string to JSON keys?
问题描述
DataContractJsonSerializer 这是.net框架中添加的不错的类可以用于将对象序列化/反序列化为JSON.
DataContractJsonSerializer this is nice class added in the .net framework which can be used to serialize/desirealize object into JSON.
现在,以下是我正在尝试的示例
Now following is the example i am trying
[Serializable] class User { public string name; public string userId; }
现在是生成的输出
输出:通知结构,其中仅应使用名称",而不是k__BackingField
Output : Notice structure where only "name" is expected instead of k__BackingField
现在这是经过大量挖掘后的问题,我不确定<>和_BackingField将从何处来?
Now this is the problem after digging so much i am not sure from where <> and _BackingField is coming ?
{
"<name>k__BackingField":"test user",
"<userId>k__BackingField":100001}
推荐答案
这只是有根据的猜测.我认为这是因为您使用的是公共字段,而不是名称和用户ID的属性.
This is just an educated guess. I think it's because you're using public fields instead of properties for name and userid.
看来这也与您使用[Serializable]属性而不是[DataContract]和[DataMember]有关.请查看此帖子以获取更多详细信息:
It appears it also has to do with the fact that you are using the [Serializable] attribute instead of [DataContract] and [DataMember]. Check out this post for more detail:
这篇关于DataContractJsonSerializer生成Ghost字符串到JSON密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!