Number value changes on JSON.parse( )

天涯浪子 提交于 2021-01-29 02:04:44

问题


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?


回答1:


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)



来源:https://stackoverflow.com/questions/38070943/number-value-changes-on-json-parse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!