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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

peraphs just post, have error, (strongm)

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
425
IT
Code:
Private Sub PROVINCE()

    Dim APICall As String
    Dim Query As String
    Dim strKey As String
    Dim myXML As New MSXML2.DOMDocument60
    Dim nodes As IXMLDOMSelection

    'APICall = "[URL unfurl="true"]https://cap.openapi.it/cerca_comuni"[/URL]
    APICall = "[URL unfurl="true"]https://comuni.openapi.it/province/"[/URL]
    'Query = "?comune=ROMA"    ' use Rome as an example
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", APICall, False
        .setRequestHeader "Authorization", "Bearer ZZZZZZZZZZZZZZZZZZZZZ"
        .send
        Debug.Print .responseText
        JSONDecode Replace(.responseText, "data", "info")    ' avoid the trap that data is a reserved word in VB
    End With

End Sub
Sub JSONDecode1(JSONString)

    Dim oJSON, mydata

    With CreateObject("ScriptControl")

        .Language = "JScript"

        Set oJSON = .Eval("(" + JSONString + ")")

        [b]For Each mydata In oJSON.info.result'<<<< herror in image[/b]
            Debug.Print "PROVINCIA: " & mydata.capoluogo & ", " & mydata.istat
        Next

    End With

End Sub

output:

{
"data": {
"AG": "Agrigento",
"AL": "Alessandria",
"AN": "Ancona",
"AO": "Valle d'Aosta\/Vall\u00e9e d'Aoste",
"AP": "Ascoli Piceno",
"AQ": "L'Aquila",
"AR": "Arezzo",
"AT": "Asti",
"AV": "Avellino",
"BA": "Bari",
"BG": "Bergamo",
"BI": "Biella",
"BL": "Belluno",
"BN": "Benevento",
"BO": "Bologna",
"BR": "Brindisi",
"BS": "Brescia",
"BT": "Barletta-Andria-Trani",
"BZ": "Bolzano\/Bozen",
"CA": "Cagliari",
"CB": "Campobasso",
"CE": "Caserta",
"CH": "Chieti",
"CL": "Caltanissetta",
"CN": "Cuneo",
"CO": "Como",
"CR": "Cremona",
"CS": "Cosenza",
"CT": "Catania",
"CZ": "Catanzaro",
"EN": "Enna",
"FC": "Forl\u00ec-Cesena",
"FE": "Ferrara",
"FG": "Foggia",
"FI": "Firenze",
"FM": "Fermo",
"FR": "Frosinone",
"GE": "Genova",
"GO": "Gorizia",
"GR": "Grosseto",
"IM": "Imperia",
"IS": "Isernia",
"KR": "Crotone",
"LC": "Lecco",
"LE": "Lecce",
"LI": "Livorno",
"LO": "Lodi",
"LT": "Latina",
"LU": "Lucca",
"MB": "Monza e della Brianza",
"MC": "Macerata",
"ME": "Messina",
"MI": "Milano",
"MN": "Mantova",
"MO": "Modena",
"MS": "Massa-Carrara",
"MT": "Matera",
"NA": "Napoli",
"NO": "Novara",
"NU": "Nuoro",
"OR": "Oristano",
"PA": "Palermo",
"PC": "Piacenza",
"PD": "Padova",
"PE": "Pescara",
"PG": "Perugia",
"PI": "Pisa",
"PN": "Pordenone",
"PO": "Prato",
"PR": "Parma",
"PT": "Pistoia",
"PU": "Pesaro e Urbino",
"PV": "Pavia",
"PZ": "Potenza",
"RA": "Ravenna",
"RC": "Reggio Calabria",
"RE": "Reggio nell'Emilia",
"RG": "Ragusa",
"RI": "Rieti",
"RM": "Roma",
"RN": "Rimini",
"RO": "Rovigo",
"SA": "Salerno",
"SI": "Siena",
"SO": "Sondrio",
"SP": "La Spezia",
"SR": "Siracusa",
"SS": "Sassari",
"SU": "Sud Sardegna",
"SV": "Savona",
"TA": "Taranto",
"TE": "Teramo",
"TN": "Trento",
"TO": "Torino",
"TP": "Trapani",
"TR": "Terni",
"TS": "Trieste",
"TV": "Treviso",
"UD": "Udine",
"VA": "Varese",
"VB": "Verbano-Cusio-Ossola",
"VC": "Vercelli",
"VE": "Venezia",
"VI": "Vicenza",
"VR": "Verona",
"VT": "Viterbo",
"VV": "Vibo Valentia"
},
"message": "107 Risultati",
"success": true,
"error": null
}
 
Your returned JSON does not have a .result property defined
 
Your returned JSON does not have a .result property defined

???
 
For the below to work

[tt]For Each mydata In oJSON.info.result[/tt]

the JSON returned by your query would need a [tt]info[/tt] property (and it does - or at least it does once we have done the Replace to swap out [tt]data[/tt]), and that [tt]info[/tt] property would need a [tt]result[/tt] property - which it doesn't. The API call you are using does not return the object you seem to be expecting. Indeed, you have commented out the API call that does

JSON is basically just a text representation of an object

But let's be clear here: the issue is not a VB6 issue. I've gone about as far as I can with you on this on more than one occasion. And I am not prepared to go get a working token to do any testing, I'm afraid (the tokens I had have all stopped working)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top