How to exclude property from Json Serialization

Jak
Jak
Member
858 Points
132 Posts

Hi,

I am using Newtonsoft to serialize object. I wan to ignore some property but unable to do this.

var json=JsonConvert.SerializeObject(playerItem);

In the class:

[Serializable]
public class player
{
[System.Web.Script.Serialization.ScriptIgnore]
public string playerId { get; set; }
}

Please help

Views: 12199
Total Answered: 1
Total Marked As Answer: 0
Posted On: 04-Mar-2016 08:22

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
Teacher
4822 Points
23 Posts
         

Hi Jak,

You need to use [Newtonsoft.Json.JsonIgnore] attribute as

[Serializable]
public class BaseBallPlayerStats
{
    [Newtonsoft.Json.JsonIgnore]
    public string playerId { get; set; }
}
Posted On: 04-Mar-2016 08:37
 Log In to Chat