omegastripes / VBA-JSON-parser

Backus-Naur Form JSON Parser based on RegEx for VBA
GNU General Public License v3.0
108 stars 44 forks source link

"Invalid use of New keyword" in json_ParseObject #35

Closed karolblond closed 9 months ago

karolblond commented 9 months ago

Hi there,

I tried to test out VBA-JSON and used this simple macro from your examples:

Sub ExampleUsingJsonParser()
    Dim Json As Object
    Set Json = JsonConverter.ParseJson("{""a"":123,""b"":[1,2,3,4],""c"":{""d"":456}}")

    MsgBox (Json("c")("e"))

End Sub

However, while executing the macro I am getting the "Invalid use of New keyword" error in here:

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

precisely in this line: Set json_ParseObject = New Dictionary.

I have imported JsonCoverter.bas into my project and added reference to Microsoft Scripting Runtime, so everything should work fine.

I am using MS VBA 7.1.

Any ideas?

omegastripes commented 9 months ago

used this simple macro from your examples: ...


    Set Json = JsonConverter.ParseJson("{""a"":123,""b"":[1,2,3,4],""c"":{""d"":456}}")

There is no such code in my examples

omegastripes commented 9 months ago

However, while executing the macro I am getting the "Invalid use of New keyword" error in here: ... precisely in this line: Set json_ParseObject = New Dictionary.

Anyway, check compatibility note in How to add reference?, also make sure that there is no custom class with the same name.