4
JavaScriptSerializer serializer = new JavaScriptSerializer();
string sJSON =  serializer.Serialize(pt);

This works fine except that it also includes fields that are set as [NonSerialized] Is there a way to exclude those fields?

2 Answers 2

3

[ScriptIgnore()] is what you want

the [NonSerialized()] tag works only for binary serilaization, your example is one of Java script serialization

Sign up to request clarification or add additional context in comments.

Comments

3

I think you are looking for the ScriptIgnoreAttribute:

public class Data {

    [ScriptIgnore]
    public string Ignore;

    public string DoNotIgnore;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.