VBA-JSON解析器v2.2.3运行时不一致
我的工作使用了一个xcel工具,它具有Tim Hall编写的VBA-JSON v2.2.3解析器。(他的github页面似乎在某个时候被删除了。)以下是问题的详细信息:VBA-JSON解析器v2.2.3运行时不一致,json,vba,Json,Vba,我的工作使用了一个xcel工具,它具有Tim Hall编写的VBA-JSON v2.2.3解析器。(他的github页面似乎在某个时候被删除了。)以下是问题的详细信息: 通常需要1秒的简单(非常小)解析操作偶尔需要2-5分钟才能完成 我使用要解析的一致信息(windows版本、xcel版本和VBA-JSON版本)进行了测试,但仍然会发生随机缓慢解析 我跟踪了运行时,当它运行缓慢时,通过json\u ParseObject的do循环,每次迭代运行json\u ParseValue()所需的时间会
- 通常需要1秒的简单(非常小)解析操作偶尔需要2-5分钟才能完成
- 我使用要解析的一致信息(windows版本、xcel版本和VBA-JSON版本)进行了测试,但仍然会发生随机缓慢解析
- 我跟踪了运行时,当它运行缓慢时,通过json\u ParseObject的do循环,每次迭代运行json\u ParseValue()所需的时间会越来越长。总体结构是递归的,因此随着时间的推移,每次下降都会减慢,但通常情况下,这只需要一秒钟,因为每一组数据都足够小,不重要。(下面列出了正在使用的三种功能,以供参考)
- 我听说xcel中的一个更新出现了一个bug,其中VBA-JSON解析器的运行速度非常慢,但这个bug在100%的情况下都会出现,这个bug似乎是突然出现的
- 我们在大约30台计算机上同时运行这个程序,并且这个问题在大约一半的计算机上持续发生。但只有它们的数量差不多,哪台电脑有问题是不一致的
私有函数json\u ParseKey(json\u字符串作为字符串,ByRef json\u索引作为字符串)
'使用单引号或双引号分析键
如果VBA.Mid$(json\U字符串,json\U索引,1)=“”,或VBA.Mid$(json\U字符串,json\U索引,1)=“”,则
json_ParseKey=json_ParseString(json_字符串,json_索引)
ElseIf JsonOptions.allowunkotedkeys然后
Dim json_字符作为字符串
当json_Index>0和json_Index时执行此操作,这看起来与。解决方案是确保使用最新版本这看起来与。解决方案是确保使用最新版本你是说这个github?我注意到,您已经表示,对于之前报告的问题,您希望能够始终如一地看到这个问题。但是,您是否注意到最新的VBA JSON版本出现了此问题?@QHarr,是的,这看起来是正确的!出于某种原因,2.2.3版自述文件中的链接毫无用处,但这看起来像是正确的链接!我会更新它并做更多的测试。谢谢到目前为止,一切都运转良好。谢谢你的链接!好啊我留下了答案,以防别人看到。如果错误再次出现,请务必让我知道,我将删除答案。你是说这个github?我注意到,您已经表示,对于之前报告的问题,您希望能够始终如一地看到这个问题。但是,您是否注意到最新的VBA JSON版本出现了此问题?@QHarr,是的,这看起来是正确的!出于某种原因,2.2.3版自述文件中的链接毫无用处,但这看起来像是正确的链接!我会更新它并做更多的测试。谢谢到目前为止,一切都运转良好。谢谢你的链接!好啊我留下了答案,以防别人看到。请让我知道,如果错误再次出现,我会删除答案。
Private Function json_ParseObject(json_String As String, ByRef json_Index As Long) As Dictionary
Dim json_Key As String
Dim json_NextChar As String
Set json_ParseObject = New Dictionary
json_SkipSpaces json_String, json_Index
If VBA.Mid$(json_String, json_Index, 1) <> "{" Then
Err.Raise 10001, "JSONConverter", json_ParseErrorMessage(json_String, json_Index, "Expecting '{'")
Else
json_Index = json_Index + 1
Do
json_SkipSpaces json_String, json_Index
If VBA.Mid$(json_String, json_Index, 1) = "}" Then
json_Index = json_Index + 1
Exit Function
ElseIf VBA.Mid$(json_String, json_Index, 1) = "," Then
json_Index = json_Index + 1
json_SkipSpaces json_String, json_Index
End If
json_Key = json_ParseKey(json_String, json_Index)
json_NextChar = json_Peek(json_String, json_Index)
If json_NextChar = "[" Or json_NextChar = "{" Then
Set json_ParseObject.Item(json_Key) = json_ParseValue(json_String, json_Index)
Else
json_ParseObject.Item(json_Key) = json_ParseValue(json_String, json_Index)
End If
Loop
End If
End Function
Private Function json_ParseValue(json_String As String, ByRef json_Index As Long) As Variant
json_SkipSpaces json_String, json_Index
Select Case VBA.Mid$(json_String, json_Index, 1)
Case "{"
Set json_ParseValue = json_ParseObject(json_String, json_Index)
Case "["
Set json_ParseValue = json_ParseArray(json_String, json_Index)
Case """", "'"
json_ParseValue = json_ParseString(json_String, json_Index)
Case Else
If VBA.Mid$(json_String, json_Index, 4) = "true" Then
json_ParseValue = True
json_Index = json_Index + 4
ElseIf VBA.Mid$(json_String, json_Index, 5) = "false" Then
json_ParseValue = False
json_Index = json_Index + 5
ElseIf VBA.Mid$(json_String, json_Index, 4) = "null" Then
json_ParseValue = Null
json_Index = json_Index + 4
ElseIf VBA.InStr("+-0123456789", VBA.Mid$(json_String, json_Index, 1)) Then
json_ParseValue = json_ParseNumber(json_String, json_Index)
Else
Err.Raise 10001, "JSONConverter", json_ParseErrorMessage(json_String, json_Index, "Expecting 'STRING', 'NUMBER', null, true, false, '{', or '['")
End If
End Select
End Function
Private Function json_ParseKey(json_String As String, ByRef json_Index As Long) As String
' Parse key with single or double quotes
If VBA.Mid$(json_String, json_Index, 1) = """" Or VBA.Mid$(json_String, json_Index, 1) = "'" Then
json_ParseKey = json_ParseString(json_String, json_Index)
ElseIf JsonOptions.AllowUnquotedKeys Then
Dim json_Char As String
Do While json_Index > 0 And json_Index <= Len(json_String)
json_Char = VBA.Mid$(json_String, json_Index, 1)
If (json_Char <> " ") And (json_Char <> ":") Then
json_ParseKey = json_ParseKey & json_Char
json_Index = json_Index + 1
Else
Exit Do
End If
Loop
Else
Err.Raise 10001, "JSONConverter", json_ParseErrorMessage(json_String, json_Index, "Expecting '""' or '''")
End If
' Check for colon and skip if present or throw if not present
json_SkipSpaces json_String, json_Index
If VBA.Mid$(json_String, json_Index, 1) <> ":" Then
Err.Raise 10001, "JSONConverter", json_ParseErrorMessage(json_String, json_Index, "Expecting ':'")
Else
json_Index = json_Index + 1
End If
End Function