JSON.parse() 上的数值变化 [英] Number value changes on JSON.parse( )

查看:136
本文介绍了JSON.parse() 上的数值变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Node/Express 向 data.records.userId 在解析时发生变化.

为什么会这样?我在这里错过了什么吗?他们为什么要这样做?

解决方案

JSON 解析器的数量太高

关于 javascript 中可能的最高值的信息:
JavaScript 最高的是什么一个 Number 可以在不损失精度的情况下访问的整数值?

这里提供了一个解决方案:
节点.Node.js 是否有任何正确的方法来解析大量的 JSON?(long, bigint, int64)

I'm using Node/Express to make API requests to the unofficial Vine API.

The data that the GET https://api.vineapp.com/users/search/ route returns changes on parsing.

My code is the following:

request({ url: 'https://api.vineapp.com/users/search/' + username }, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(typeof body,'UNPARSED BODY:', body);

  body = JSON.parse(body);

  console.log(typeof body,'PARSED BODY:', JSON.stringify(body, null, 2));

  cb(null, body)
});

This is what is returns: The data.records.userId changes on parsing.

Why does this happen? Am I missing something here? Why would they do that?

解决方案

The number is too high for the JSON parser

Info about the highest possible value in javascript:
What is JavaScript's highest integer value that a Number can go to without losing precision?

There is a solution provided here:
node.js is there any proper way to parse JSON with large numbers? (long, bigint, int64)

这篇关于JSON.parse() 上的数值变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆