# 数字id太长导致删除&更新失败

{% embed url="<https://v.douyin.com/rRKnDnY/>" %}

{% embed url="<https://www.bilibili.com/video/BV1gS4y1b7eF/?share_source=copy_web&vd_source=7921250291864d635c60fe929b49e3f3>" %}

大家看这删除功能啊

他总是报操作失败

那原因其实就是他传给后台的这个 id

不对我们先来

抓下包哈

大家看他后台返回的 id 是54560结尾

但是呢他提示出来的是包括（删除）请求的时候这个 id

也是54600都不对

为什么会这样呢

我们先把刚才这个

正确的 id 放到控制台里直接执行

大家看！他也变成54600了

也就是说：在 js 里面

整型他有精度问题

只要超过2的53次方

都是（有可能）有问题的

也就是说：超过这个数都有可能会有问题

我们来试一下啊

大家看！不对了

大家看

都不对了

那这个问题呢

回头有机会我们单独出一期视频

跟浮点数的精度咱们一起来分享

今天我们主要来说一下

怎么解决这个问题

第一个方法最简单有效

就是把接口返回的这个数据

变成字符串类型的

直接就可以解决

那如果后台接口改不了

其实也很简单

比如我们现在这个项目

他用的是axios嘛

我们先首先把这个 json-bigint

这个包导进来

然后呢

我们在这个 axios 请求这里做一下改动

先把这个bigint导进来

倒进来以后

我们在这在请求的地方加一个参数

叫 transformResponse

这 copilot 给提示了

就这样写

把这个加上一个类似于这个

响应的转换器

用这个 bigint 去 parse

这样的话呢

我们在使用的地方完全不用改

大家看现在他打印的这个

响应的结果啊

这个 id 是不对的

然后呢我们把这保存一下

刷新

好我们再看一下

0 id

他就变成 big number 了

这时我们再点删除打卡

这个 id 就对了

那还有一种方法呢就是

我们在这导进来以后哈

我们可以这样写

cont JSONBigIntStr = ...

调一下这个

里边传一个 storeAsString = true 也就说他自动

把这个转成String类型的

然后我们用这个去做格式化

好再刷新一下

好再看一下

他看这就是一个做串类型的了

这样就更没有问题了


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sunzsh.gitbook.io/xiaoshan.bug/shu-zi-id-tai-chang-dao-zhi-shan-chu-geng-xin-shi-bai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
