当我发布对象时
{
"Title": "LookingForGroup",
"Description": "Descrptjasag",
"CreatorName":"[email protected]",
"Price":"4"
}
在邮递员中,我得到一个json异常,说:
System.Text.Json.JsonException:检测到可能的对象周期不支持。这可能是由于周期或对象深度大于最大允许深度32。
我的帖子类别
public class Post
{
public string Id { get; set; }
public string Title { get; set; }
public ApplicationUser Creator { get; set; }
public string CreatorId { get; set; }
public string Description { get; set; }
public PostType PostType { get; set; }
public decimal Price { get; set; }
public ICollection<Bid> Bids { get; set; }
}
我的模特
public class PostInputModel
{
public string Title { get; set; }
public string Description { get; set; }
public string Price { get; set; }
public string CreatorName { get; set; }
}
我的控制器
[HttpPost]
public async Task<ActionResult<PostInputModel>> PostPost(PostInputModel input)
{
Post post = new Post()
{
Id = Guid.NewGuid().ToString(),
Title = input.Title,
Creator = _context.Users.Where(x => x.UserName == input.CreatorName).FirstOrDefault(),
Description = input.Description,
PostType = PostType.Help,
Price = 4
};
_context.Posts.Add(post);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (PostExists(post.Id))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtAction("GetPost", post);
}
我的用户类别
public class ApplicationUser : IdentityUser
{
public ICollection<Bid> Bids { get; set; }
public ICollection<Post> FreelanceService { get; set; }
}
您可以添加有关您的课程的更多详细信息吗?也许您有循环引用。如果不是这种情况,请检查此问题1
。NET Core 3.0中的JsonSerializer不支持循环引用。支持此建议的提案正在#41002中进行研究。如果您认为这不是一个循环,而只是拥有一个非常深的层次结构,则可以将JsonSerializerOptions.MaxDepth设置为大于默认值。