Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better version that reads the object properties and makes into a table with headers: #495

Open
orooro opened this issue Feb 21, 2024 · 1 comment

Comments

@orooro
Copy link

orooro commented Feb 21, 2024

          Better version that reads the object properties and makes into a table with headers:
Option Explicit

Public Sub IterateOverACollection()

    Dim jsonString As String
    jsonString = "[{""row"":1, ""a"":""0007"", ""b"":""Blue"", ""c"":""2008""}, {""row"":2, ""a"":null, ""b"":"""", ""c"":""1709""}]"
    
    Dim myCollection As Collection
    Set myCollection = ParseJson(jsonString)
    
    Dim myDictionary As Dictionary
    Dim i As Long, j As Long
    
    Dim StartCell As Range
    Set StartCell = ActiveSheet.Range("A1")
    
    Set myDictionary = myCollection(1)
    For j = 1 To myDictionary.Count
        StartCell.Offset(0, j - 1) = myDictionary.Keys(j - 1)
        StartCell.Offset(0, j - 1).Font.Bold = True
    Next j
    
    For i = 1 To myCollection.Count
        Set myDictionary = myCollection(i)
        For j = 1 To myDictionary.Count
           StartCell.Offset(i, j - 1) = myDictionary.Items(j - 1)
        Next j
    Next i
    
End Sub

screen shot 2018-03-23 at 4 29 41 pm

Originally posted by @zgrose in #329 (comment)

@orooro
Copy link
Author

orooro commented Feb 21, 2024

Hi, I have tried the routine with this Json but I get error in "line":5 I think it is because of the array "failure_reason":{"type": "validation", "fields":["email"]},

could you help me on this?
thank you very much in advance

{"line":5, "email": "institutcastelldelquer @gmail. com", "sms_phone":null, "result": "failure", "failure_reason":{"type": "validation", "fields":["email"]} the full json is this[{"line":1, "email":"", "sms_phone":null, "result": "failure", "failure_reason": "header", "created_at": "2024-02-13T11:01:19:000Z"},

Json complete

[{"line":1,"email":"","sms_phone":null,"result":"failure","failure_reason":"header","created_at":"2024-02-13T11:01:19.000Z"},{"line":2,"email":"[email protected]","sms_phone":"","result":"success","failure_reason":null,"created_at":"2024-02-13T11:01:19.000Z"},{"line":3,"email":"[email protected]","sms_phone":"","result":"success","failure_reason":null,"created_at":"2024-02-13T11:01:19.000Z"},{"line":4,"email":"[email protected]","sms_phone":"","result":"success","failure_reason":null,"created_at":"2024-02-13T11:01:19.000Z"},{"line":5,"email":"institutcastelldelquer @gmail.com","sms_phone":null,"result":"failure","failure_reason":{"type":"validation","fields":["email"]},"created_at":"2024-02-13T11:01:23.000Z"},{"line":6,"email":"[email protected]","sms_phone":"","result":"success","failure_reason":null,"created_at":"2024-02-13T11:01:26.000Z"},{"line":7,"email":"[email protected]","sms_phone":"","result":"success","failure_reason":null,"created_at":"2024-02-13T11:01:26.000Z"}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant