Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 Parsing JSON 1

Status
Not open for further replies.

Swi

Programmer
Feb 4, 2002
1,963
0
36
US
Are there any native ways to parse JSON in VB6?

I have the following JSON string and would like to parse it. These will be dynamic as I am pulling from a API.

Code:
{"result_count":1, "results":[{"taxonomies": [{"state": "NY", "code": "207R00000X", "primary": true, "license": "999999", "desc": "Internal Medicine"}], "addresses": [{"city": "ALBANY", "address_2": "SUITE 999", "telephone_number": "999-999-9999", "state": "NY", "postal_code": "122056433", "address_1": "5 XXXXXXX DR", "country_code": "US", "country_name": "United States", "address_type": "DOM", "address_purpose": "LOCATION"}, {"city": "ALBANY", "address_2": "SUITE 200", "telephone_number": "518-438-0019", "state": "NY", "postal_code": "122056433", "address_1": "5 PALISADES DR", "country_code": "US", "country_name": "United States", "address_type": "DOM", "address_purpose": "MAILING"}], "created_epoch": 1308182400, "identifiers": [], "other_names": [], "number": 1346535499, "last_updated_epoch": 1414540800, "basic": {"status": "A", "credential": "D.O.", "first_name": "TEST", "last_name": "IT", "middle_name": "X", "name": "TEST IT", "gender": "M", "sole_proprietor": "NO", "last_updated": "2014-10-29", "enumeration_date": "2011-06-16"}, "enumeration_type": "NPI-1"}]}

Thanks.

Swi
 
Did you have any luck finding anything in json.org?
There is a link at the bottom of the page to VB-JSON


---- Andy

There is a great need for a sarcasm font.
 
Hi, yes, just downloaded that. Now just trying to get down the syntax for parsing out the information in the JSON. Having some difficulty with that. Thanks.

Swi
 
Getting items in the JSON is giving me issues. Top level items I am grabbing just fine.

Code:
        sRequest = "[URL unfurl="true"]https://npiregistry.cms.hhs.gov/api?first_nameADAM&last_name=LAMMLY&state=NY&limit=1&skip="[/URL]
    
        'Assumed MSXML2 core service well installed
        Set oxmlhttp2 = New MSXML2.ServerXMLHTTP
        oxmlhttp2.Open "get", sRequest, False
        oxmlhttp2.setRequestHeader "Content-Type", "application/json"
        oxmlhttp2.send sRequest
        Set oXMLDoc2 = New MSXML2.DOMDocument
        oXMLDoc2.async = False
        If oxmlhttp2.readyState = 4 Or oxmlhttp2.Status = 200 Then
          result = oXMLDoc2.loadXML(oxmlhttp2.responseText)
        Else
          result = False
        End If
        MsgBox oxmlhttp2.responseText

        Dim p As Object
        Set p = JSON.parse(oxmlhttp2.responseText)
        
        MsgBox "Result Count: " & p.Item("result_count")
        MsgBox "Results Taxonomies State: " & p.Item("results").Item("taxonomies").Item("state")

Swi
 
I think I got it.

Code:
        MsgBox "Result Count: " & p.Item("result_count")
        MsgBox "Results City: " & p.Item("results").Item(1).Item("addresses").Item(1).Item("city")
        MsgBox "Results State: " & p.Item("results").Item(1).Item("addresses").Item(1).Item("state")
        MsgBox "Results State: " & p.Item("results").Item(1).Item("addresses").Item(1).Item("postal_code")

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top