开发者

Omit object property during json serialization

I'm using MVC Controller. Json method in order to send json result object to my javascript function.

From time to time I want to omit one of my object's property from the json result object.

How can I achive it?

This is my .NET object:

    public class jsTreeModel
    {
        public string Data { get; set; }
        public JsTree开发者_运维问答Attribute Att { get; set; }
        public string State { get; set; }
        public List<jsTreeModel> Children { get; set; }
    }

I this case I want to omit the 'Children' property from the json result.

Any idea?


If you are using Json.NET as your serializer, you can omit a property fairly simply:

public class jsTreeModel
{
    public string Data { get; set; }
    public JsTreeAttribute Att { get; set; }
    public string State { get; set; }
    [JsonIgnore]
    public List<jsTreeModel> Children { get; set; }
}

I hope this helps you!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜