因此,VBA.CallByName也可以访问数组中的元素以及找到数组的长度
'Tools->References->'Microsoft script Control 1.0; {0E59F1D2-1FBE-11D0-8FF2-00A0D10038BC}; C:WindowsSysWOW64msscript.ocxPrivate Sub TestJSonParsingArrayWithCallByName() Dim oscriptEngine As scriptControl Set oscriptEngine = New scriptControl oscriptEngine.Language = "Jscript" Dim sJsonString As String sJsonString = "[ 1234, 2345 ]" Dim objJSON As Object Set objJSON = oscriptEngine.eval("(" + sJsonString + ")") '* Using VBA.CallByName we get the length of the array Dim lLength As Long lLength = VBA.CallByName(objJSON, "length", VbGet) Debug.Assert lLength = 2 '* Believe or not one uses "0","1",.... with callbyname to get an element Debug.Assert VBA.CallByName(objJSON, "0", VbGet) = 1234 Debug.Assert VBA.CallByName(objJSON, "1", VbGet) = 2345End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)