0

Getting Type Mismatch (Error 13) while using Json PArser in Excel MAcro

Below are the code :

Sub getJsonValue()
    Dim FSO As New FileSystemObject
    Dim JsonTS As TextStream
    Set JsonTS = FSO.OpenTextFile("C:\Users\Card_Link.json", ForReading)
    JsonText = JsonTS.ReadAll
    JsonTS.Close
    Set Json = ParseJson(JsonText)
    Set JsonRows = Json("rows")
    i = 2
    For Each Item In Json
         Sheet5.Cells(i, 1).Value = Item("name")
        'Sheet5.Cells(i, 2).Value = Item("results")("name")
        'Sheet5.Cells(i, 3).Value = Item("results")("responsecode")
        i = i + 1
    Next
    MsgBox ("complete")
End Sub

Getting error on this statement Sheet5.Cells(i, 1).Value = Item("name")

Can someone please help me to resolve this.

Thanks RJ

1 Answer 1

1

Without having any experience with ParseJson, try one of these:

Sheet5.Cells(i, 1).value = item

Sheet5.Cells(i, 1).value = item(0)

Sheet5.Cells(i, 1).value = item.Name

If still none of these works, try like this:

For Each item In Json
    Stop
     Sheet5.Cells(i, 1).value = item("name")
    'Sheet5.Cells(i, 2).Value = Item("results")("name")
    'Sheet5.Cells(i, 3).Value = Item("results")("responsecode")
    i = i + 1
Next

On the stop, select item, press Shift+F9 and see what do you have in item.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your reply. Sheet5.Cells(i, 1).value = item - this statement is working but I want to get the subitem values. I tried item(0), item.Name and item(Name) but nothing is working. Can you please help me
@user8472243 - have you tried Shift + F9? What happened?
Sorry for late response. In "Item", I am getting correct value now but when I am going to get the next level value like item.name or item(name). Its showing error - 424 (Run time Error) says "Object Required" on this statement - Sheet5.Cells(i, 2).Value = Item.Name
@user8472243 - how about item("name") or item("Name")?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.