Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove k__BackingField from json when Deserialize

I am getting the k_BackingField in my returned json after serializing a xml file to a .net c# object.

I've added the DataContract and the DataMember attribute to the .net c# object but then I get nothing on the json, client end.

[XmlRoot("person")] [Serializable] public class LinkedIn {     [XmlElement("id")]     public string ID { get; set; }      [XmlElement("industry")]     public string Industry { get; set; }      [XmlElement("first-name")]     public string FirstName { get; set; }      [XmlElement("last-name")]     public string LastName { get; set; }     [XmlElement("headline")] } 

Example of the returned json:

home: Object <FirstName>k__BackingField: "Storefront" <LastName>k__BackingField: "Doors" 
like image 624
Filling The Stack is What I DO Avatar asked Oct 23 '12 01:10

Filling The Stack is What I DO


People also ask

What is k_BackingField?

k_BackingField has been added to indicate an auto-property has been serialised. If you refactor the auto-property to a property and a backing field then the problem would go away.

Which JSON method is used to deserialize the data?

Net object to JSON string use the Serialize method. It's possible to deserialize JSON string to . Net object using Deserialize<T> or DeserializeObject methods.

Can you deserialize JSON?

A common way to deserialize JSON is to first create a class with properties and fields that represent one or more of the JSON properties. Then, to deserialize from a string or a file, call the JsonSerializer. Deserialize method.

How does JSON deserialize work?

JSON is a format that encodes objects in a string. Serialization means to convert an object into that string, and deserialization is its inverse operation (convert string -> object). If you serialize this result it will generate a text with the structure and the record returned.


1 Answers

Remove [Serializable] from your class

like image 124
Safaa Elgendi Avatar answered Sep 18 '22 13:09

Safaa Elgendi