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.

    4
    • 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 meCommentedAug 22, 2017 at 23:44
    • @user8472243 - have you tried Shift + F9? What happened?
      – Vityata
      CommentedAug 23, 2017 at 7:46
    • 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.NameCommentedSep 1, 2017 at 4:43
    • @user8472243 - how about item("name") or item("Name")?
      – Vityata
      CommentedSep 1, 2017 at 8:14

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.