.Net Core:控制Controller.Json方法生成的Json [英] .Net Core: controlling Json generated by Controller.Json method
本文介绍了.Net Core:控制Controller.Json方法生成的Json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
默认情况下,Controller.Json为类的每个公共成员生成JSON.我如何更改此设置,以使某些成员被忽略.请注意,我正在使用.Net Core.
By default, Controller.Json generates JSON for each public member of a class. How can I change this so that some members are ignored. Please note that I am using .Net Core.
示例:
[HttpGet("/api/episodes")]
public IActionResult GetEpisodes()
{
var episodes = _podcastProvider.Get();
return Json(episodes);
}
谢谢.
推荐答案
您可以使用Newtonsoft.Json
命名空间中可用的[JsonIgnore]
属性,如下所示:
You can use [JsonIgnore]
attribute that available in Newtonsoft.Json
namespace like below:
public class Model
{
public int Id { get; set; }
public string Name { get; set; }
[JsonIgnore]
public int Age { get; set; }
}
这篇关于.Net Core:控制Controller.Json方法生成的Json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文