【问题标题】:My ASP.NET Core API not returning all rows我的 ASP.NET Core API 没有返回所有行
【发布时间】:2019-08-18 17:01:00
【问题描述】:

我的 ASP.NET Core API 只返回 40 行中的前两行。

我试过了

services.AddMvc().AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

它将 VS 代码发送到一个无限循环。关于在哪里寻找解决这个问题的任何想法?我正在使用浏览器和邮递员来使用 api 并获得相同的结果。

[EnableCors]
[HttpGet]
public ActionResult<IEnumerable<Fuaxclient>> GetClient()
{
    return _context.clientList;
}

我希望得到大约 48 行的正确 json 代码。相反,我得到 2 行和损坏的 json。我从 FireFox Web 控制台收到此错误

error: null​
headers: Object { normalizedNames: Map(0), lazyUpdate: null, headers: Map(0) }
​message: "Http failure response for https://fuaxclientapi.azurewebsites.net/api/fuaxclient: 500 Internal Server Error"​
name: "HttpErrorResponse"
​ok: false
​status: 500
​statusText: "Internal Server Error"
​url: "https://fuaxclientapi.azurewebsites.net/api/fuaxclient"

如果您想尝试 API 以了解我在说什么,该 API 仍在运行。 ​

【问题讨论】:

  • 你能显示fuaxclientapi的操作吗?
  • azure 上的日志是怎么说的。如果您生成 500 错误,则它应该生成服务器端日志。
  • API https://fuaxclientapi.azurewebsites.net/api/fuaxclient 正在返回无效的 JSON 结构。您需要在响应末尾附加带有 ] 的字符串,以便正确解析此 JSON 字符串。
  • 我将如何访问该日志?我仍在学习导航 azore 仪表板

标签: c# json asp.net-core asp.net-core-webapi


【解决方案1】:

好的,经过大量的挖掘和研究并将我的头撞在桌子上,我找到了我的问题。我的数据库中有 NULL,API 在 NULL 处停止。

【讨论】:

    【解决方案2】:
    status: 500
    ​statusText: "Internal Server Error"
    

    由于错误500 本身表明服务器上存在错误,在这种情况下,https://fuaxclientapi.azurewebsites.net/api/fuaxclient 声明的 url(端点 api)有问题。

    它返回无效的 json 作为验证 here

    返回值需要在api中固定。

    【讨论】:

    • 我相信fuaxclientapi.azurewebsites.net/api/fuaxclient 是问题中的操作代码。你对“我如何追踪这个问题”的回答是“解决你的问题”
    • 当我请求单个“客户端”时,它返回正确的 json。为什么批量查询会有所不同?
    猜你喜欢
    • 1970-01-01
    • 2017-01-11
    • 2023-03-20
    • 2018-12-09
    • 1970-01-01
    • 2021-05-30
    • 1970-01-01
    • 2018-09-27
    • 2017-12-01
    相关资源
    最近更新 更多