我正在使用此链接中的 VBA JSON 转换器 https://github.com/VBA-tools/VBA-JSON
我有一个包含 16 位数字的单元格,但是当我将其转换为 JSON 时,它会在不带引号的情况下进行转换。
所以应该是这样的
{
ID: "1525879763214789"
}
但显示是这样的
{
ID: 1525879763214789
}
我尝试将单元格格式更改为文本,但这也没有帮助
编辑:
Private Sub CommandButton3_Click()
Dim z As Integer, items As New Collection, myitem As New Dictionary
Dim rng As Range
Dim cell As Variant
Dim FSO As New FileSystemObject
Dim JsonTS As TextStream
Set JsonTS = FSO.OpenTextFile("test.json", ForReading)
JsonText = JsonTS.ReadAll
JsonTS.Close
Set JSON = ParseJson(JsonText)
JSON("root")(1)("STATUS_RESPONSE")("RESULT")(1)("USER")("BUSINESS_ID") = Sheets(1).Cells(2, 1).Value
JSON("root")(1)("STATUS_RESPONSE")("RESULT")(1)("USER")("ID") = Sheets(1).Cells(2, 2).Value
myfile = Application.ActiveWorkbook.Path & "\test.json"
Open myfile For Output As #1
Print #1, ConvertToJson(JSON, Whitespace:=2)
MsgBox ("Exported to JSON file")
Close #1
End Sub
我的 JSON
{
"root": [{
"STATUS_RESPONSE": {
"STATUS": {
"STATUS": {
"OWNER": "root"
}
},
"REQ_ID": "00000",
"RESULT": [{
"USER": {
"BUSINESS_ID": "A",
"USER_NUMBER": "45",
"LANGUAGE": "F",
"ID" : "1525879763214789"
}
},
{
"USER_SESSION": {
"USER_ID": "0000001009",
"HELP_URL": "http://google.com"
}
},
{
"USER_ACCESS": {
"SERVICES_ROLE": "true",
"JOURNALLING": "true"
}
}]
}
}]
}
最佳答案
在下面的代码部分中,将 UseDoubleForLargeNumbers
标志设置为 True,这样应该可以工作。
Dim myfile As Variant
myfile = Application.ActiveWorkbook.Path & "C:\Temp\test_out.json"
Open myfile For Output As #1
JsonConverter.JsonOptions.UseDoubleForLargeNumbers = True
Print #1, ConvertToJson(JSON, Whitespace:=2)
'MsgBox ("Exported to JSON file")
Close #1
关于json - VBA Json转换器不能转换超过15位数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51306698/