Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) ipstack.com IPv4 Geolocation LookupDemonstrates how to lookup Geolocation data for an IPv4 address using the ipstack.com REST API.
Use ChilkatAx-win32.pkg Procedure Test Handle hoHttp String sJsonStr Handle hoJson Boolean iSuccess String sIp String sV_type String sContinent_code String sContinent_name String sCountry_code String sCountry_name String sRegion_code String sRegion_name String sCity String sZip String sLatitude String sLongitude String sLocationGeoname_id String sLocationCapital String sLocationCountry_flag String sLocationCountry_flag_emoji String sLocationCountry_flag_emoji_unicode String sLocationCalling_code Boolean iLocationIs_eu Integer i Integer iCount_i String sCode String sName String sNative String sTemp1 Boolean bTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End // Lookup an IPv4 address: 149.250.207.170 (this was a randomly chosen address) Get ComQuickGetStr Of hoHttp "http://api.ipstack.com/149.250.207.170?access_key=YOUR_ACCESS_KEY" To sJsonStr Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Set ComEmitCompact Of hoJson To False Get ComLoad Of hoJson sJsonStr To iSuccess Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // Sample output: // Use this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON // { // "ip": "149.250.207.170", // "type": "ipv4", // "continent_code": "EU", // "continent_name": "Europe", // "country_code": "DE", // "country_name": "Germany", // "region_code": null, // "region_name": null, // "city": null, // "zip": null, // "latitude": 51.2993, // "longitude": 9.491, // "location": { // "geoname_id": null, // "capital": "Berlin", // "languages": [ // { // "code": "de", // "name": "German", // "native": "Deutsch" // } // ], // "country_flag": "http:\/\/assets.ipstack.com\/flags\/de.svg", // "country_flag_emoji": "\ud83c\udde9\ud83c\uddea", // "country_flag_emoji_unicode": "U+1F1E9 U+1F1EA", // "calling_code": "49", // "is_eu": true // } // } Get ComStringOf Of hoJson "ip" To sIp Get ComStringOf Of hoJson "type" To sV_type Get ComStringOf Of hoJson "continent_code" To sContinent_code Get ComStringOf Of hoJson "continent_name" To sContinent_name Get ComStringOf Of hoJson "country_code" To sCountry_code Get ComStringOf Of hoJson "country_name" To sCountry_name Get ComStringOf Of hoJson "region_code" To sRegion_code Get ComStringOf Of hoJson "region_name" To sRegion_name Get ComStringOf Of hoJson "city" To sCity Get ComStringOf Of hoJson "zip" To sZip Get ComStringOf Of hoJson "latitude" To sLatitude Get ComStringOf Of hoJson "longitude" To sLongitude Get ComStringOf Of hoJson "location.geoname_id" To sLocationGeoname_id Get ComStringOf Of hoJson "location.capital" To sLocationCapital Get ComStringOf Of hoJson "location.country_flag" To sLocationCountry_flag Get ComStringOf Of hoJson "location.country_flag_emoji" To sLocationCountry_flag_emoji Get ComStringOf Of hoJson "location.country_flag_emoji_unicode" To sLocationCountry_flag_emoji_unicode Get ComStringOf Of hoJson "location.calling_code" To sLocationCalling_code Get ComBoolOf Of hoJson "location.is_eu" To iLocationIs_eu Move 0 To i Get ComSizeOfArray Of hoJson "location.languages" To iCount_i While (i < iCount_i) Set ComI Of hoJson To i Get ComStringOf Of hoJson "location.languages[i].code" To sCode Get ComStringOf Of hoJson "location.languages[i].name" To sName Get ComStringOf Of hoJson "location.languages[i].native" To sNative Move (i + 1) To i Loop End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.