之前在Java 遇過同樣問題, 解決方案是在getter 中加入annotation. 而在.net core 中, 則需要透過修改startup().
在Startup.cs 中修改ConfigureService() 如下便可:
public void ConfigureServices(IServiceCollection services) { services.AddMvc().AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
Leave a Reply