我正在使用 .NET 6 和使用物體框架的 API。場景,我收到 Soup API 然后創建新的 API,當我測驗我得到正確的結果時輸出是 json 結果,但是在我在 Azure 上發布專案后,API 沒有顯示我想要的。
[HttpGet("[action]")]
public IActionResult GetExamService(string id, string Examcodes, string codes)
{
try
{
ExamServiceClient exam = new();
ExamDetailsStructure abilitiesExam = new();
ExamResults.PersonNameBody ApplicantName = new();
var response = exam.GetExamResultAsync(id, Examcodes, codes).Result.Item;
if (!response.GetType().ToString().Equals(abilitiesExam.GetType().ToString()))
{
throw new NullReferenceException("no data found " id);
}
abilitiesExam = (ExamDetailsStructure)response;
ApplicantName = (QyiasExamResults.PersonNameBody)abilitiesExam.ApplicantName.Item;
ExamDetailsBody ExamDetailsBody = new()
{
ExamSpecialty = abilitiesExam.ExamSpecialty.ToString() ?? "",
ExamResultTypeEnSpecified = abilitiesExam.ExamResult.ExamResultTypeEnSpecified.ToString() ?? "",
};
return Ok(new
{
ExamDetailsBody = ExamDetailsBody
});
}
catch (NullReferenceException ex)
{
ErrorResponse error = new(ex.Message, StatusCodes.Status404NotFound);
return StatusCode((int)HttpStatusCode.NotFound, error);
}
catch
{
ErrorResponse error = new("internal server error", StatusCodes.Status500InternalServerError);
return StatusCode((int)HttpStatusCode.InternalServerError, error);
}
}

Azure 輸出此結果:

uj5u.com熱心網友回復:
這解決了我的問題。我使用 JSON 序列化器 NewtonsoftJson
//JSON Serializer
builder.Services.AddControllers().AddNewtonsoftJson(options =>
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore)
.AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
有關包Microsoft Ignite和從 nuget Microsoft.AspNetCore.Mvc.NewtonsoftJson下載的更多詳細資訊
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/517096.html
上一篇:帶有物體框架的Windows表單在.theninclude()上僅在已發布版本上崩潰,而不是在除錯中
下一篇:已達到套接字最大fds
