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
(Objective-C) ipdata.co IPv4 Geolocation LookupSee more Geolocation ExamplesDemonstrates how to lookup Geolocation data for an IPv4 address using the ipdata.co API.
#import <CkoHttp.h> #import <NSString.h> #import <CkoJsonObject.h> // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkoHttp *http = [[CkoHttp alloc] init]; NSString *jsonStr = [http QuickGetStr: @"https://api.ipdata.co/149.250.207.170?api-key=MY_API_KEY"]; if (http.LastMethodSuccess == NO) { NSLog(@"%@",http.LastErrorText); return; } CkoJsonObject *json = [[CkoJsonObject alloc] init]; json.EmitCompact = NO; BOOL success = [json Load: jsonStr]; NSLog(@"%@",[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" // } NSString *ip = 0; BOOL is_eu; NSString *city = 0; NSString *region = 0; NSString *region_code = 0; NSString *country_name = 0; NSString *country_code = 0; NSString *continent_name = 0; NSString *continent_code = 0; NSString *latitude = 0; NSString *longitude = 0; NSString *asn = 0; NSString *organisation = 0; NSString *postal = 0; NSString *calling_code = 0; NSString *flag = 0; NSString *emoji_flag = 0; NSString *emoji_unicode = 0; NSString *currencyName = 0; NSString *currencyCode = 0; NSString *currencySymbol = 0; NSString *currencyNative = 0; NSString *currencyPlural = 0; NSString *time_zoneName = 0; NSString *time_zoneAbbr = 0; NSString *time_zoneOffset = 0; BOOL time_zoneIs_dst; NSString *time_zoneCurrent_time = 0; BOOL threatIs_tor; BOOL threatIs_proxy; BOOL threatIs_anonymous; BOOL threatIs_known_attacker; BOOL threatIs_known_abuser; BOOL threatIs_threat; BOOL threatIs_bogon; NSString *count = 0; int i; int count_i; NSString *name = 0; NSString *native = 0; ip = [json StringOf: @"ip"]; is_eu = [json BoolOf: @"is_eu"]; city = [json StringOf: @"city"]; region = [json StringOf: @"region"]; region_code = [json StringOf: @"region_code"]; country_name = [json StringOf: @"country_name"]; country_code = [json StringOf: @"country_code"]; continent_name = [json StringOf: @"continent_name"]; continent_code = [json StringOf: @"continent_code"]; latitude = [json StringOf: @"latitude"]; longitude = [json StringOf: @"longitude"]; asn = [json StringOf: @"asn"]; organisation = [json StringOf: @"organisation"]; postal = [json StringOf: @"postal"]; calling_code = [json StringOf: @"calling_code"]; flag = [json StringOf: @"flag"]; emoji_flag = [json StringOf: @"emoji_flag"]; emoji_unicode = [json StringOf: @"emoji_unicode"]; currencyName = [json StringOf: @"currency.name"]; currencyCode = [json StringOf: @"currency.code"]; currencySymbol = [json StringOf: @"currency.symbol"]; currencyNative = [json StringOf: @"currency.native"]; currencyPlural = [json StringOf: @"currency.plural"]; time_zoneName = [json StringOf: @"time_zone.name"]; time_zoneAbbr = [json StringOf: @"time_zone.abbr"]; time_zoneOffset = [json StringOf: @"time_zone.offset"]; time_zoneIs_dst = [json BoolOf: @"time_zone.is_dst"]; time_zoneCurrent_time = [json StringOf: @"time_zone.current_time"]; threatIs_tor = [json BoolOf: @"threat.is_tor"]; threatIs_proxy = [json BoolOf: @"threat.is_proxy"]; threatIs_anonymous = [json BoolOf: @"threat.is_anonymous"]; threatIs_known_attacker = [json BoolOf: @"threat.is_known_attacker"]; threatIs_known_abuser = [json BoolOf: @"threat.is_known_abuser"]; threatIs_threat = [json BoolOf: @"threat.is_threat"]; threatIs_bogon = [json BoolOf: @"threat.is_bogon"]; count = [json StringOf: @"count"]; i = 0; count_i = [[json SizeOfArray: @"languages"] intValue]; while (i < count_i) { json.I = [NSNumber numberWithInt: i]; name = [json StringOf: @"languages[i].name"]; native = [json StringOf: @"languages[i].native"]; i = i + 1; } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.