需要对象/类型不匹配

时间:2016-01-29 11:02:06

标签: java json vba excel-vba excel

我有一个代码来从Jira Rest Api请求问题,当我有一个简单的字段时,我遇到了所需的Type对象的麻烦,当我把它与Object类型放在一起时,它需要一个String。我需要解析json并将信息放入Excel中......这里的代码是:

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() As String, k_fields() As String, k_project() As String, k_issuetype() As String, k_status() As String, k_summary() As String, k_report() As String, k_created() As String, k_updated() As String, k_assignee() As String, k_priority() As String, k_resolution() As String, k_resolved() As String, k_timespent() As String, k_timeestimated() As String, k_projecttype() As String

    Dim issue As Variant, ki As Variant, kf As Variant, kproject As Variant, kissuetype As Variant, kstatus As Variant, ksummary As Variant, kreport As Variant, kcreated As Variant, kupdated As Variant, kassignee As Variant, kpriority As Variant, kresolution As Variant, kresolved As Variant, ktimespent As Variant, ktimeestimated As Variant

    Dim project_name_issue As String, project_key_issue As String, key_issue As String, issue_type_name As String, issue_type_description As String, status_name_issue As String, summary_key As String, report_key As String, created  As String, updated As String, assignee As String, priority As String, resolution As String, resolved As String, timespent As String, timeestimated As String, today As String

    today = Date

    ThisWorkbook.Sheets("RawData").Range("A" & 1).value = "Project"
    ThisWorkbook.Sheets("RawData").Range("B" & 1).value = "Key"
    ThisWorkbook.Sheets("RawData").Range("C" & 1).value = "Issues Type"
    ThisWorkbook.Sheets("RawData").Range("D" & 1).value = "Status"
    ThisWorkbook.Sheets("RawData").Range("E" & 1).value = "Summary"
    ThisWorkbook.Sheets("RawData").Range("F" & 1).value = "Report"
    ThisWorkbook.Sheets("RawData").Range("G" & 1).value = "Created"
    ThisWorkbook.Sheets("RawData").Range("H" & 1).value = "Updated"
    ThisWorkbook.Sheets("RawData").Range("I" & 1).value = "Assignee"
    ThisWorkbook.Sheets("RawData").Range("J" & 1).value = "Priority"
    ThisWorkbook.Sheets("RawData").Range("K" & 1).value = "Resolution"
    ThisWorkbook.Sheets("RawData").Range("L" & 1).value = "Resolved"
    ThisWorkbook.Sheets("RawData").Range("M" & 1).value = "Time Spent"
    ThisWorkbook.Sheets("RawData").Range("N" & 1).value = "Time estimated"
    ThisWorkbook.Sheets("RawData").Range("O" & 1).value = "Today"

    For Each issue In issues
        total = total + 1
        Key = decode.GetKeys(issue)
        For Each ki In Key
            If ki = "key" Then
                key_issue = decode.GetProperty(issue, ki)
                ThisWorkbook.Sheets("RawData").Range("B" & total).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
                    If kf = "project" Then
                      Set issue_project = decode.GetObjectProperty(field, kf)
                      k_project = decode.GetKeys(issue_project)
                      For Each kproject In k_project
                        If kproject = "name" Then
                           project_name_issue = decode.GetProperty(issue_project, kproject)
                           ThisWorkbook.Sheets("RawData").Range("A" & total).value = project_name_issue 
                        End If
                        If kproject = "key" Then
                           project_key_issue = decode.GetProperty(issue_project, kproject)

                        End If
                      Next
                    End If
                    If kf = "issuetype" Then
                        Set issue_type = decode.GetObjectProperty(field, kf)
                        k_issuetype = decode.GetKeys(issue_type)
                        For Each kissuetype In k_issuetype
                            If kissuetype = "name" Then
                                issue_type_name = decode.GetProperty(issue_type, kissuetype)
                                ThisWorkbook.Sheets("RawData").Range("C" & total).value = issue_type_name 
                            End If
                            If kissuetype = "description" Then
                                issue_type_description = decode.GetProperty(issue_type, kissuetype)
                            End If
                        Next
                    End If
                    If kf = "status" Then
                        Set issue_status = decode.GetObjectProperty(field, kf)
                        k_status = decode.GetKeys(issue_status)
                        For Each kstatus In k_status
                            If kstatus = "status" Then
                                status_name_issue = decode.GetProperty(issue_status, kstatus)
                                ThisWorkbook.Sheets("RawData").Range("D" & total).value = status_name_issue 'i=lastrow
                            End If
                        Next
                    End If
                    If kf = "summary" Then
                        issue_summary = decode.GetProperty(field, kf)
                        ThisWorkbook.Sheets("RawData").Range("E" & total).value = summary_key
                    End If
                    If kf = "reporter" Then
                        Set issue_report = decode.GetObjectProperty(field, kf)
                        k_report = decode.GetKeys(issue_report)
                        For Each kreport In k_report
                            If kreport = "displayName" Then
                                report_key = decode.GetProperty(issue_report, kreport)
                                ThisWorkbook.Sheets("RawData").Range("F" & total).value = report_key
                            End If
                        Next
                    End If
                    If kf = "created" Then
                        Set issue_created = decode.GetProperty(field, kf)
                        ThisWorkbook.Sheets("RawData").Range("G" & total).value = created
                    End If
                    If kf = "updated" Then
                        Set issue_updated = decode.GetProperty(field, kf)
                        ThisWorkbook.Sheets("RawData").Range("H" & total).value = updated
                    End If
                    If kf = "assignee" Then
                        Set issue_assignee = decode.GetObjectProperty(field, kf)
                        k_assignee = decode.GetKeys(issue_assignee)
                        For Each kassignee In k_assignee
                            If kassignee = "name" Then
                                assignee = decode.GetProperty(issue_assignee, kassignee)
                                ThisWorkbook.Sheets("RawData").Range("I" & total).value = assignee
                            End If
                        Next
                    End If
                    If kf = "priority" Then
                        Set issue_priority = decode.GetObjectProperty(field, kf)
                        k_priority = decode.GetKeys(issue_priority)
                        For Each kpriority In k_priority
                            If kpriority = "name" Then
                                priority = decode.GetProperty(issue_priority, kpriority)
                                ThisWorkbook.Sheets("RawData").Range("J" & total).value = priority
                            End If
                        Next
                    End If
                     If kf = "resolution" Then
                        Set issue_resolution = decode.GetObjectProperty(field, kf)
                        k_resolution = decode.GetKeys(issue_resolution)
                        For Each kresolution In k_resolution
                            If kresolution = "name" Then
                                resolution = decode.GetProperty(issue_resolution, kresolution)
                                ThisWorkbook.Sheets("RawData").Range("K" & total).value = resolution
                            End If
                        Next
                    End If
                    If kf = "resolutiondate" Then
                        Set kresolved = decode.GetProperty(field, kf)
                        ThisWorkbook.Sheets("RawData").Range("L" & total).value = kresolved
                    End If
                    If kf = "timespent" Then
                        Set ktimespent = decode.GetProperty(field, kf)
                        ThisWorkbook.Sheets("RawData").Range("M" & total).value = ktimespent
                    End If
                    If kf = "timeestimated" Then
                        Set ktimeestimated = decode.GetProperty(issue_time_estimated, kf)
                        ThisWorkbook.Sheets("RawData").Range("N" & total).value = ktimeestimated
                    End If
                Next
            End If
        Next
        ThisWorkbook.Sheets("RawData").Range("O" & total).value = today
    Next
End Sub

当我在json中有一个节点时,它是一个样本场,而不是一个阵列,我有麻烦,比如在创建,更新,时间等等......等等。

0 个答案:

没有答案