4

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; }

Now following is the output generated

Output : Notice structure where only "name" is expected instead of k__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}
Anil Namde
  • 6,452
  • 11
  • 63
  • 100

1 Answers1

3

This is just an educated guess. I think it's because you're using public fields instead of properties for name and userid.

Edit: 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:

C# automatic property deserialization of JSON

Community
  • 1
  • 1
Rob Windsor
  • 6,744
  • 1
  • 21
  • 26
  • Thanks for answering ........ i figured out that the C# 3.0's implicit properties causing it as compiler adds code for doing that. This is getting reflected when serialization takes place. – Anil Namde May 25 '10 at 06:14