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
(Swift 3,4,5...) ipdata.co IPv4 Geolocation LookupSee more Geolocation ExamplesDemonstrates how to lookup Geolocation data for an IPv4 address using the ipdata.co API.
func chilkatTest() { // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. let http = CkoHttp()! var jsonStr: String? = http.quickGetStr("https://api.ipdata.co/149.250.207.170?api-key=MY_API_KEY") if http.lastMethodSuccess == false { print("\(http.lastErrorText!)") return } let json = CkoJsonObject()! json.emitCompact = false var success: Bool = json.load(jsonStr) print("\(json.emit()!)") // Sample output: // Use this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON // { // "ip": "149.250.207.170", // "is_eu": true, // "city": null, // "region": null, // "region_code": null, // "country_name": "Germany", // "country_code": "DE", // "continent_name": "Europe", // "continent_code": "EU", // "latitude": 51.2993, // "longitude": 9.491, // "asn": "AS15854", // "organisation": "EntServ Deutschland GmbH", // "postal": null, // "calling_code": "49", // "flag": "https://ipdata.co/flags/de.png", // "emoji_flag": "\ud83c\udde9\ud83c\uddea", // "emoji_unicode": "U+1F1E9 U+1F1EA", // "languages": [ // { // "name": "German", // "native": "Deutsch" // } // ], // "currency": { // "name": "Euro", // "code": "EUR", // "symbol": "\u20ac", // "native": "\u20ac", // "plural": "euros" // }, // "time_zone": { // "name": "Europe/Berlin", // "abbr": "CEST", // "offset": "+0200", // "is_dst": true, // "current_time": "2019-04-20T23:54:30.715507+02:00" // }, // "threat": { // "is_tor": false, // "is_proxy": false, // "is_anonymous": false, // "is_known_attacker": false, // "is_known_abuser": false, // "is_threat": false, // "is_bogon": false // }, // "count": "2" // } var ip: String? var is_eu: Bool var city: String? var region: String? var region_code: String? var country_name: String? var country_code: String? var continent_name: String? var continent_code: String? var latitude: String? var longitude: String? var asn: String? var organisation: String? var postal: String? var calling_code: String? var flag: String? var emoji_flag: String? var emoji_unicode: String? var currencyName: String? var currencyCode: String? var currencySymbol: String? var currencyNative: String? var currencyPlural: String? var time_zoneName: String? var time_zoneAbbr: String? var time_zoneOffset: String? var time_zoneIs_dst: Bool var time_zoneCurrent_time: String? var threatIs_tor: Bool var threatIs_proxy: Bool var threatIs_anonymous: Bool var threatIs_known_attacker: Bool var threatIs_known_abuser: Bool var threatIs_threat: Bool var threatIs_bogon: Bool var count: String? var i: Int var count_i: Int var name: String? var native: String? ip = json.string(of: "ip") is_eu = json.bool(of: "is_eu") city = json.string(of: "city") region = json.string(of: "region") region_code = json.string(of: "region_code") country_name = json.string(of: "country_name") country_code = json.string(of: "country_code") continent_name = json.string(of: "continent_name") continent_code = json.string(of: "continent_code") latitude = json.string(of: "latitude") longitude = json.string(of: "longitude") asn = json.string(of: "asn") organisation = json.string(of: "organisation") postal = json.string(of: "postal") calling_code = json.string(of: "calling_code") flag = json.string(of: "flag") emoji_flag = json.string(of: "emoji_flag") emoji_unicode = json.string(of: "emoji_unicode") currencyName = json.string(of: "currency.name") currencyCode = json.string(of: "currency.code") currencySymbol = json.string(of: "currency.symbol") currencyNative = json.string(of: "currency.native") currencyPlural = json.string(of: "currency.plural") time_zoneName = json.string(of: "time_zone.name") time_zoneAbbr = json.string(of: "time_zone.abbr") time_zoneOffset = json.string(of: "time_zone.offset") time_zoneIs_dst = json.bool(of: "time_zone.is_dst") time_zoneCurrent_time = json.string(of: "time_zone.current_time") threatIs_tor = json.bool(of: "threat.is_tor") threatIs_proxy = json.bool(of: "threat.is_proxy") threatIs_anonymous = json.bool(of: "threat.is_anonymous") threatIs_known_attacker = json.bool(of: "threat.is_known_attacker") threatIs_known_abuser = json.bool(of: "threat.is_known_abuser") threatIs_threat = json.bool(of: "threat.is_threat") threatIs_bogon = json.bool(of: "threat.is_bogon") count = json.string(of: "count") i = 0 count_i = json.size(ofArray: "languages").intValue while i < count_i { json.i = i name = json.string(of: "languages[i].name") native = json.string(of: "languages[i].native") i = i + 1 } } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.