Angular 无法解析巨大的 JSON

发布于 2025-01-10 16:18:08 字数 3897 浏览 0 评论 0原文

我有一个用 nativescript 制作的应用程序,我遇到的问题是,当我从后端接收数据时,我收到一个错误:

Angular code:

   return await this._clientesService
            .getFromBackend()
            .toPromise()
            .then(async (res: any) => {
                return res.data
            })

My service code:

getFromBackend() {
        return this._http.get(`${ConfigService[ConfigService.ACTIVE_SERVER]}clientes?get-all=true&vendedor=${ConfigService.SELECTED_VENDEDOR_ID}`)
    }

The error:

JS: ERRORRR {
JS:   "headers": {
JS:     "normalizedNames": {},
JS:     "lazyUpdate": null
JS:   },
JS:   "status": 200,
JS:   "statusText": "OK",
JS:   "url": "http://172.16.0.229:8000/api/clientes?get-all=true&vendedor=999",
JS:   "ok": false,
JS:   "name": "HttpErrorResponse",
JS:   "message": "Http failure during parsing for http://172.16.0.229:8000/api/clientes?get-all=true&vendedor=999",
JS:   "error": {
JS:     "error": {},
JS:     "text": "{\"data\":[{\"cliente\":0,\"digito\":0,\"cli_pessoa\":0,\"nome\":null,\"ruc\":null,\"email\":null,\"cidade\":null,\"rg\":null,\"fone\":null,\"endereco\":null,\"condV\":1},{\"cliente\":5911,\"digito\":59115,\"cli_pessoa\":2,\"nome\":null,\"ruc\":\"3671157 8\",\"email\":null,\"cidade\":\"HERNANDARIAS\",\"rg\":null,\"fone\":null,\"endereco\":null,\"condV\":1},{\"cliente\":47174,\"digito\":471741,\"cli_pessoa\":2,\"nome\":null,\"ruc\":\" -\",\"email\":null,\"cidade\":\"C D E \",\"rg\":null,\"fone\":null,\"endereco\":null,\"condV\":1},{\"cliente\":54543,\"digito\":545430,\"cli_pessoa\":2,\"nome\":\" ADOLFO BENITEZ\",\"ruc\":\...

I returned those datas from my back Laravel 5.7 中的结束:

return response()->json([
    "data" => ClientResource::collection($res),
    "query" => $request->cliente,
    "current_page" => $res->currentPage(),
    "last_page" => $res->lastPage(),
], 200);

问题是我的数据库中有 60.000 条记录,当我返回 10 或 50 条时,它可以工作,但是当我返回更多记录时,它不起作用,我不知道为什么,

在邮递员中它工作得很好,我只在我的角度应用程序中遇到这个问题

,我已经尝试

{responseType: 'text'}

在我的http.get上添加,它可以工作,但是当我执行 JSON.parse() 时抛出一个错误,

JS: ERRORRR SyntaxError: Unexpected token , in JSON at position 58756

我已经用 JSON 确认了我返回的 JSON验证器并且有效

所有这些看起来我的 json 有一些错误,但我没有,因为如果我以 null 返回我的 json 值,我会得到相同的错误,这是我返回的 json:

{
"data": [
    {
        "cliente": 13277,
        "digito": 132779,
        "cli_pessoa": 2,
        "nome": " ",
        "ruc": "1182263-5",
        "email": null,
        "cidade": "PDTE FRANCO",
        "rg": null,
        "fone": "",
        "endereco": null,
        "condV": 1
    },
    {
        "cliente": 14539,
        "digito": 145390,
        "cli_pessoa": 2,
        "nome": " ",
        "ruc": null,
        "email": null,
        "cidade": "MAYOR OTA O",
        "rg": null,
        "fone": "",
        "endereco": null,
        "condV": 1
    },
    {
        "cliente": 55231,
        "digito": 552315,
        "cli_pessoa": 2,
        "nome": " ",
        "ruc": null,
        "email": null,
        "cidade": "PDTE FRANCO",
        "rg": null,
        "fone": null,
        "endereco": null,
        "condV": 1
    },
    {
        "cliente": 58235,
        "digito": 582351,
        "cli_pessoa": 2,
        "nome": " ",
        "ruc": " 0",
        "email": null,
        "cidade": "C D E ",
        "rg": null,
        "fone": null,
        "endereco": null,
        "condV": 1
    },
    {
        "cliente": 6891,
        "digito": 68912,
        "cli_pessoa": 2,
        "nome": " ",
        "ruc": null,
        "email": null,
        "cidade": "HERNANDARIAS",
        "rg": null,
        "fone": "",
        "endereco": null,
        "condV": 1
    }
],
"query": null,
"current_page": 5,
"last_page": 11608

}

有人可以帮助我吗?

I have an app made in angular with nativescript, the problem I have is, when I receive the data from the back end, I receive it like an error:

Angular code:

   return await this._clientesService
            .getFromBackend()
            .toPromise()
            .then(async (res: any) => {
                return res.data
            })

My service code:

getFromBackend() {
        return this._http.get(`${ConfigService[ConfigService.ACTIVE_SERVER]}clientes?get-all=true&vendedor=${ConfigService.SELECTED_VENDEDOR_ID}`)
    }

The error:

JS: ERRORRR {
JS:   "headers": {
JS:     "normalizedNames": {},
JS:     "lazyUpdate": null
JS:   },
JS:   "status": 200,
JS:   "statusText": "OK",
JS:   "url": "http://172.16.0.229:8000/api/clientes?get-all=true&vendedor=999",
JS:   "ok": false,
JS:   "name": "HttpErrorResponse",
JS:   "message": "Http failure during parsing for http://172.16.0.229:8000/api/clientes?get-all=true&vendedor=999",
JS:   "error": {
JS:     "error": {},
JS:     "text": "{\"data\":[{\"cliente\":0,\"digito\":0,\"cli_pessoa\":0,\"nome\":null,\"ruc\":null,\"email\":null,\"cidade\":null,\"rg\":null,\"fone\":null,\"endereco\":null,\"condV\":1},{\"cliente\":5911,\"digito\":59115,\"cli_pessoa\":2,\"nome\":null,\"ruc\":\"3671157 8\",\"email\":null,\"cidade\":\"HERNANDARIAS\",\"rg\":null,\"fone\":null,\"endereco\":null,\"condV\":1},{\"cliente\":47174,\"digito\":471741,\"cli_pessoa\":2,\"nome\":null,\"ruc\":\" -\",\"email\":null,\"cidade\":\"C D E \",\"rg\":null,\"fone\":null,\"endereco\":null,\"condV\":1},{\"cliente\":54543,\"digito\":545430,\"cli_pessoa\":2,\"nome\":\" ADOLFO BENITEZ\",\"ruc\":\...

I returned those datas from my back end made in Laravel 5.7:

return response()->json([
    "data" => ClientResource::collection($res),
    "query" => $request->cliente,
    "current_page" => $res->currentPage(),
    "last_page" => $res->lastPage(),
], 200);

The problem is that I had 60.000 records on my database and when I return 10 or 50 it's work, but when I return more of that it doesn't work and I don't know why,

In postman it work perfectly, I have this issue only in my angular application

I already try adding

{responseType: 'text'}

on my http.get, it's work but when I do JSON.parse() throws an error

JS: ERRORRR SyntaxError: Unexpected token , in JSON at position 58756

I already confirm my returned JSON with a JSON validator and is valid

All of that It's look like I have some error with my json but I don't because I got the same error if I return my json values in null, this is my json returned:

{
"data": [
    {
        "cliente": 13277,
        "digito": 132779,
        "cli_pessoa": 2,
        "nome": " ",
        "ruc": "1182263-5",
        "email": null,
        "cidade": "PDTE FRANCO",
        "rg": null,
        "fone": "",
        "endereco": null,
        "condV": 1
    },
    {
        "cliente": 14539,
        "digito": 145390,
        "cli_pessoa": 2,
        "nome": " ",
        "ruc": null,
        "email": null,
        "cidade": "MAYOR OTA O",
        "rg": null,
        "fone": "",
        "endereco": null,
        "condV": 1
    },
    {
        "cliente": 55231,
        "digito": 552315,
        "cli_pessoa": 2,
        "nome": " ",
        "ruc": null,
        "email": null,
        "cidade": "PDTE FRANCO",
        "rg": null,
        "fone": null,
        "endereco": null,
        "condV": 1
    },
    {
        "cliente": 58235,
        "digito": 582351,
        "cli_pessoa": 2,
        "nome": " ",
        "ruc": " 0",
        "email": null,
        "cidade": "C D E ",
        "rg": null,
        "fone": null,
        "endereco": null,
        "condV": 1
    },
    {
        "cliente": 6891,
        "digito": 68912,
        "cli_pessoa": 2,
        "nome": " ",
        "ruc": null,
        "email": null,
        "cidade": "HERNANDARIAS",
        "rg": null,
        "fone": "",
        "endereco": null,
        "condV": 1
    }
],
"query": null,
"current_page": 5,
"last_page": 11608

}

can someone help me on this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2025-01-17 16:18:08

我认为你的数据太大了,不知何故你的后端或角度限制了它。你永远不应该返回这种类型的大数据。

尝试限制 Laravel Collection 中的选定字段,或对它们进行分页。

I think your data is too large and somehow either your backend or angular limiting it. You should never return this type of huge data.

Try to limit selected fields in your Laravel Collection, or paginate them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文