我正在通过此链接https://github.com/VBA-tools/VBA-JSON
使用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"
}
}]
}
}]
}
答案 0 :(得分:2)
在下面的代码部分中,将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