美文网首页
解决后端long类型精度丢失

解决后端long类型精度丢失

作者: Sasoli | 来源:发表于2019-04-08 18:41 被阅读0次

1、安装jison

npm install jison

2、下载 词表文件 - lexfile - jsonlint.l、语法文件 - grammFile - jsonlint.y
https://github.com/zaach/jsonlint

3、修改jsonlint.y词法文件:当整数超过了安全范围的时候,使用字符串表示

JSONNumber
    : NUMBER
        { // If integer is too long, use string to store it
            $$ = yytext == String(Number(yytext))? Number(yytext): yytext;
        }
    ;

4、生成我们要的 jsonlint.js

jison jsonlint.y jsonlint.l

5、引入 jsonlint.js 至项目
script标签引入

  <script src="//s.newscdn.cn/x/E6PcmDjiR.js"></script>

6、修改request.js

.then(response => {
      if (newOptions.method === 'DELETE' || response.status === 204) {
        return response.text();
      }
      return response.json();
    })

改为:

.then(response => {
      if (newOptions.method === 'DELETE' || response.status === 204) {
        return response.text();
      }
      return response.text();
    })
    .then(text => {
      return jsonlint.parse(text)
    })

相关文章

网友评论

      本文标题:解决后端long类型精度丢失

      本文链接:https://www.haomeiwen.com/subject/dzmpiqtx.html