我的代码遇到了麻烦,我不知道为什么......在这一行中“Key = decode.GetKeys(issue)”引发了这个问题标题中提到的错误。
Public Sub Import_JSON_From_URL(url As JiraJSONGet)
ThisWorkbook.Sheets("RawData").Activate
result = url.LoadJson
Dim total As Long
total = getLastRow()
doInit
Dim Keys() As String
Keys = decode.GetKeys(JsonObject)
Dim issues As Object
Set issues = decode.GetObjectProperty(JsonObject, Keys(4))
Dim field, issue_project, issue_type, issue_status, issue_summary, issue_report, issue_created, issue_updated, issue_assignee, issue_priority, issue_resolution, issue_resolved, issue_time_spent, issue_time_estimated, issue_project_type As Object
Dim Key(), k_fields(), k_project(), k_issuetype(), k_status(), k_summary(), k_report(), k_created(), k_updated(), k_assignee(), k_priority(), k_resolution(), k_resolved(), k_timespent(), k_timeestimated(), k_projecttype() As String
Dim issue, ki, kf, kproject, kissuetype, kstatus, ksummary, kreport, kcreated, kupdated, kassignee, kpriority, kresolution, kresolved, ktimespent, ktimeestimated As Variant
Dim project_name_issue, project_key_issue, key_issue, issue_type_name, issue_type_description, status_name_issue, summary_key, report_key, created, updated, assignee, priority, resolution, resolved, timespent, timeestimated, today As String
For Each issue In issues
Key = decode.GetKeys(issue)
For Each ki In Key
If ki = "key" Then
key_issue = decode.GetProperty(issue, ki)
ThisWorkbook.Sheets("RawData").Range("A" & total + 1).value = key_issue
End If
If ki = "fields" Then
Set field = decode.GetObjectProperty(issue, ki)
k_fields = decode.GetKeys(field)
For Each kf In k_fields
我有一个名为JSONDecoder的类,其中包含GetKeys函数:
Public Function GetKeys(ByVal JsonObject As Object) As String()
Dim length As Integer
Dim KeysArray() As String
Dim KeysObject As Object
Dim index As Integer
Dim Key As Variant
Dim value As Variant
Set KeysObject = ScriptEngine.Run("getKeys", JsonObject)
length = GetProperty(KeysObject, "length")
ReDim KeysArray(length - 1)
index = 0
For Each Key In KeysObject
KeysArray(index) = Key
index = index + 1
Next
GetKeys = KeysArray
'value = GetProperty(JsonObject, "issues")
'Set value = GetObjectProperty(JsonObject, "issues")
End Function
答案 0 :(得分:0)
不确定您的问题在哪里。 我测试了从常规函数和使用类返回一个字符串数组,并且两者都工作正常,但是你声明你的代码甚至都不会编译。 您的问题必须在其他地方。
模块代码:
Sub Test()
Dim result() As String
result = Test1
Dim i As Integer
For i = 0 To 3
Debug.Print result(i)
Next
Dim c As New clsTest
result = c.CreateStrings
For i = 0 To 3
Debug.Print result(i)
Next
End Sub
Function Test1() As String()
Dim s() As String
ReDim s(3)
Dim i As Integer
For i = 0 To 3
s(i) = "blah" & i
Next
Test1 = s
End Function
班级代码:
Public Function CreateStrings() As String()
Dim r() As String
Dim i As Integer
ReDim r(3)
For i = 0 To 3
r(i) = "class blah" & i
Next
CreateStrings = r
End Function