我对API进行了Http调用,该API返回了一些数据。 数据如下:
Sub fileSave()
'
Dim newFileName As String, originalFileName As String, fileSaveName As String, fileNamePathSaved As String, fileNameSaved As String
Dim response As VbMsgBoxResult, currentRoute As String
'
ThisWorkbook.RefreshAll
ActiveWorkbook.Save ' save the current workbook before messing with it
Application.DisplayAlerts = False ' turns off alerts and messages
' Save file name and path into a variable
originalFileName = ActiveWorkbook.FullName ' gets the fullname with path
' originalFilePath = ActiveWorkbook.Path ' grabs the current path
Dim usingReplace As String
usingReplace = Replace(originalFileName, ".xlsm", ".xlsx")
ActiveWorkbook.SaveAs Filename:=usingReplace, FileFormat:=xlOpenXMLWorkbook
fileNameSaved = ActiveWorkbook.Name ' grabs the name of the saved file
Workbooks.Open Filename:=originalFileName 'reopens the original workbook file
Application.DisplayAlerts = True ' turns the alerts and messages back on
'provide an opportinity to clear the incident report flag
' If incidentFiled = True Then response = MsgBox("Do you want to clear the Incident Report?", vbInformation + vbOKCancel, "Incident Report Form")
If response = vbOK Then incidentFiled = False
'close the newly made file
' Workbooks(fileNameSaved).Close True ' sub terminates at this point
'
End Sub
现在,问题出在数据库中的ID,就像ID: 7728806673365567677 因此,有效ID的后3位数字为677,但是从API返回的数据包含000,因此:
有效期:7728806673365567677
无效:7728806673365567000
我想知道这是什么问题。也许ID可以是字符串而不是数字吗?
谢谢您的建议。
编辑:现在我看到后端中的数据实际上是一个字符串: “ 7728806673365567000” 但是Http调用将其更改为Number吗?
答案 0 :(得分:2)
它与NativeScript无关。您可以将其称为JavaScript的限制,已超出JavaScript支持的最大安全整数限制。如果您也在浏览器环境中尝试此操作,结果将相同。
因此,正如您已经提到的,使用String而不是Number可以解决此问题。
答案 1 :(得分:2)
基于
Number.MAX_SAFE_INTEGER
9007199254740991
var d=7728806673365567677 ;
未定义
d.toString()
“ 7728806673365567000”
typeof d
“数字”
Number.isSafeInteger(7728806673365567677 )
false
Number.isSafeInteger(7728806673365567)
true
如此
var data = {
"id": 7728806673365567677,
"title": "Status Unknown"
};
data.id;
“ 7728806673365567677”
和
var data = {
"id": "7728806673365567677",
"title": "Status Unknown"
};
data.id;
7728806673365567000
$data= array(
'id' => 7728806673365567677,
'title' => 'Status Unknown',
);
echo json_encode($data,JSON_NUMERIC_CHECK);
应解决此问题并返回
{
"id": "7728806673365567677",
"title": "Status Unknown"
};
您需要安装一个名为“ php5-json”的软件包
答案 2 :(得分:1)
是的,您应该以字符串形式威胁它。它大于最大值。 JS 2 ^ 53-1或9007199254740991中可能的数字。
由于其被截断,所以取出的数字被零代替。我不知道这种特定行为来自何处,但这似乎正在发生。
请参阅: What is JavaScript's highest integer value that a number can go to without losing precision?
答案 3 :(得分:1)
您可以使用BigInteger NPM模块来解决此问题,也可以使用一些解析器来解决此问题,请参见