27
Jsonを使用したWeb APIでの応答のシリアル化に失敗しました
ASP.NET MVC 5 Web APIを使用しています。すべてのユーザーに相談したい。 私が書いてapi/usersこれを受け取りました: 「 'ObjectContent`1'タイプは、コンテンツタイプ 'application / json; charset = utf-8'の応答本文のシリアル化に失敗しました」 WebApiConfigで、すでに次の行を追加しました: HttpConfiguration config = new HttpConfiguration(); config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType); config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; しかし、それでも機能しません。 データを返すための私の関数はこれです: public IEnumerable<User> GetAll() { using (Database db = new Database()) { return db.Users.ToList(); } }
109
c#
asp.net
json
asp.net-web-api