添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

My issue is I want to parse a JSON response from a web api but don't know where to start, i imported the jsonconvertor.bas from the vba-json github and keep getting errors. The following is what i have so far:

Private Sub btnSearch_Click()

Dim reader As New XMLHTTP60

Dim Json As Object

reader.Open "GET", "https://itunes.apple.com/search?term=" & txtSearch & "&limit=25", False
reader.send
Set Json = JSONConvertor.ParseJson(reader.responseText)
lstSearchResponse = reader.responseText

End Sub

But I get an error of object not defined in line 6.

Once that error is complete I would like to parse the json into a list box on a form, I know I need a recordset but don't know where to go from there. My ultimate goal is to list for an item, click on it, and then click another button that will add that item to a table I have. Any help would be appreciated.

Harassment is any behavior intended to disturb or upset a person or group of people. Threats include any threat of suicide, violence, or harm to another. Any content of an adult theme or inappropriate to a community web site. Any image, link, or discussion of nudity. Any behavior that is insulting, rude, vulgar, desecrating, or showing disrespect. Any behavior that appears to violate End user license agreements, including providing product keys or links to pirated software. Unsolicited bulk mail or bulk advertising. Any link to or advocacy of virus, spyware, malware, or phishing sites. Any other inappropriate content or behavior as defined by the Terms of Use or Code of Conduct. Any image, link, or discussion related to child pornography, child nudity, or other child abuse or exploitation. Has no one been able to answer at least your last 5 questions? You receive a lot of assistance here, for the benefit of other users with similar questions, the least you could do is mark those questions that have been answered as answered before moving onto yet another question. If you feel a reply works for you, please kindly vote and mark it answered as it will be beneficial to other community members reading this thread Harassment is any behavior intended to disturb or upset a person or group of people. Threats include any threat of suicide, violence, or harm to another. Any content of an adult theme or inappropriate to a community web site. Any image, link, or discussion of nudity. Any behavior that is insulting, rude, vulgar, desecrating, or showing disrespect. Any behavior that appears to violate End user license agreements, including providing product keys or links to pirated software. Unsolicited bulk mail or bulk advertising. Any link to or advocacy of virus, spyware, malware, or phishing sites. Any other inappropriate content or behavior as defined by the Terms of Use or Code of Conduct. Any image, link, or discussion related to child pornography, child nudity, or other child abuse or exploitation. Harassment is any behavior intended to disturb or upset a person or group of people. Threats include any threat of suicide, violence, or harm to another. Any content of an adult theme or inappropriate to a community web site. Any image, link, or discussion of nudity. Any behavior that is insulting, rude, vulgar, desecrating, or showing disrespect. Any behavior that appears to violate End user license agreements, including providing product keys or links to pirated software. Unsolicited bulk mail or bulk advertising. Any link to or advocacy of virus, spyware, malware, or phishing sites. Any other inappropriate content or behavior as defined by the Terms of Use or Code of Conduct. Any image, link, or discussion related to child pornography, child nudity, or other child abuse or exploitation. Harassment is any behavior intended to disturb or upset a person or group of people. Threats include any threat of suicide, violence, or harm to another. Any content of an adult theme or inappropriate to a community web site. Any image, link, or discussion of nudity. Any behavior that is insulting, rude, vulgar, desecrating, or showing disrespect. Any behavior that appears to violate End user license agreements, including providing product keys or links to pirated software. Unsolicited bulk mail or bulk advertising. Any link to or advocacy of virus, spyware, malware, or phishing sites. Any other inappropriate content or behavior as defined by the Terms of Use or Code of Conduct. Any image, link, or discussion related to child pornography, child nudity, or other child abuse or exploitation.

yes I did I referenced the Microsoft Scripting Runtime, and I still get a runtime error of 424: object required. Here is the code that I am using, it is unfinished of course but right now I am trying to parse the data:

Private Sub btnSearch_Click()

Dim reader As New XMLHTTP60

Dim Json As Object

'send request to itunes

reader.Open "GET", "https://itunes.apple.com/search?term=" & txtSearch & "&limit=25", False

reader.send

'parse the request from itunes

Set Json = JSONConvertor.ParseJson(reader.responseText)

'display parsed request in listbox

Text10 = Json

'add selected list item to table

End Sub

Where I am getting an error is Line 7 (set Json). What object is required isn't the Dim Json as Object the required object?

Harassment is any behavior intended to disturb or upset a person or group of people. Threats include any threat of suicide, violence, or harm to another. Any content of an adult theme or inappropriate to a community web site. Any image, link, or discussion of nudity. Any behavior that is insulting, rude, vulgar, desecrating, or showing disrespect. Any behavior that appears to violate End user license agreements, including providing product keys or links to pirated software. Unsolicited bulk mail or bulk advertising. Any link to or advocacy of virus, spyware, malware, or phishing sites. Any other inappropriate content or behavior as defined by the Terms of Use or Code of Conduct. Any image, link, or discussion related to child pornography, child nudity, or other child abuse or exploitation.

But you're trying to use XMLHTTP60 so you need to reference that library.

Microsoft XML, v6.0

Or better yet, use late binding and avoid the entire hassel of reference libraries.

--
Daniel Pineault
Microsoft MVP 2010-2021
Harassment is any behavior intended to disturb or upset a person or group of people. Threats include any threat of suicide, violence, or harm to another. Any content of an adult theme or inappropriate to a community web site. Any image, link, or discussion of nudity. Any behavior that is insulting, rude, vulgar, desecrating, or showing disrespect. Any behavior that appears to violate End user license agreements, including providing product keys or links to pirated software. Unsolicited bulk mail or bulk advertising. Any link to or advocacy of virus, spyware, malware, or phishing sites. Any other inappropriate content or behavior as defined by the Terms of Use or Code of Conduct. Any image, link, or discussion related to child pornography, child nudity, or other child abuse or exploitation. Harassment is any behavior intended to disturb or upset a person or group of people. Threats include any threat of suicide, violence, or harm to another. Any content of an adult theme or inappropriate to a community web site. Any image, link, or discussion of nudity. Any behavior that is insulting, rude, vulgar, desecrating, or showing disrespect. Any behavior that appears to violate End user license agreements, including providing product keys or links to pirated software. Unsolicited bulk mail or bulk advertising. Any link to or advocacy of virus, spyware, malware, or phishing sites. Any other inappropriate content or behavior as defined by the Terms of Use or Code of Conduct. Any image, link, or discussion related to child pornography, child nudity, or other child abuse or exploitation.

So I found the issue,  i was forgetting a line of code. The JSONConverter works, for some reason I had to remove it then import it back in to my module.  But the converter works now I am on a new issue that pertains to this and I made a new question about it here:

Add items to listbox - Microsoft Community .

The code I used for this is below:

reader.Open "GET", SearchURL & SearchTerm & SearchMedia & SearchEntity & SearchLimit, False

reader.send

Set Json = JsonConverter.ParseJson(reader.responseText)
Debug.Print JsonConverter.ConvertToJson(Json, Whitespace:=2)

make sure you dim Json as object. I followed the first example oh the GitHub page I downloaded this converter from.

GitHub - VBA-tools/VBA-JSON: JSON conversion and parsing for VBA

To view the parsed data one way is to have the immediate window open in the vba editor. That's how I knew the parser was working.

Harassment is any behavior intended to disturb or upset a person or group of people. Threats include any threat of suicide, violence, or harm to another. Any content of an adult theme or inappropriate to a community web site. Any image, link, or discussion of nudity. Any behavior that is insulting, rude, vulgar, desecrating, or showing disrespect. Any behavior that appears to violate End user license agreements, including providing product keys or links to pirated software. Unsolicited bulk mail or bulk advertising. Any link to or advocacy of virus, spyware, malware, or phishing sites. Any other inappropriate content or behavior as defined by the Terms of Use or Code of Conduct. Any image, link, or discussion related to child pornography, child nudity, or other child abuse or exploitation.