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
(C) ipdata.co IPv4 Geolocation LookupSee more Geolocation ExamplesDemonstrates how to lookup Geolocation data for an IPv4 address using the ipdata.co API.
#include <C_CkHttp.h> #include <C_CkJsonObject.h> void ChilkatSample(void) { HCkHttp http; const char *jsonStr; HCkJsonObject json; BOOL success; const char *ip; BOOL is_eu; const char *city; const char *region; const char *region_code; const char *country_name; const char *country_code; const char *continent_name; const char *continent_code; const char *latitude; const char *longitude; const char *asn; const char *organisation; const char *postal; const char *calling_code; const char *flag; const char *emoji_flag; const char *emoji_unicode; const char *currencyName; const char *currencyCode; const char *currencySymbol; const char *currencyNative; const char *currencyPlural; const char *time_zoneName; const char *time_zoneAbbr; const char *time_zoneOffset; BOOL time_zoneIs_dst; const char *time_zoneCurrent_time; BOOL threatIs_tor; BOOL threatIs_proxy; BOOL threatIs_anonymous; BOOL threatIs_known_attacker; BOOL threatIs_known_abuser; BOOL threatIs_threat; BOOL threatIs_bogon; const char *count; int i; int count_i; const char *name; const char *native; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttp_Create(); jsonStr = CkHttp_quickGetStr(http,"https://api.ipdata.co/149.250.207.170?api-key=MY_API_KEY"); if (CkHttp_getLastMethodSuccess(http) == FALSE) { printf("%s\n",CkHttp_lastErrorText(http)); CkHttp_Dispose(http); return; } json = CkJsonObject_Create(); CkJsonObject_putEmitCompact(json,FALSE); success = CkJsonObject_Load(json,jsonStr); printf("%s\n",CkJsonObject_emit(json)); // 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" // } ip = CkJsonObject_stringOf(json,"ip"); is_eu = CkJsonObject_BoolOf(json,"is_eu"); city = CkJsonObject_stringOf(json,"city"); region = CkJsonObject_stringOf(json,"region"); region_code = CkJsonObject_stringOf(json,"region_code"); country_name = CkJsonObject_stringOf(json,"country_name"); country_code = CkJsonObject_stringOf(json,"country_code"); continent_name = CkJsonObject_stringOf(json,"continent_name"); continent_code = CkJsonObject_stringOf(json,"continent_code"); latitude = CkJsonObject_stringOf(json,"latitude"); longitude = CkJsonObject_stringOf(json,"longitude"); asn = CkJsonObject_stringOf(json,"asn"); organisation = CkJsonObject_stringOf(json,"organisation"); postal = CkJsonObject_stringOf(json,"postal"); calling_code = CkJsonObject_stringOf(json,"calling_code"); flag = CkJsonObject_stringOf(json,"flag"); emoji_flag = CkJsonObject_stringOf(json,"emoji_flag"); emoji_unicode = CkJsonObject_stringOf(json,"emoji_unicode"); currencyName = CkJsonObject_stringOf(json,"currency.name"); currencyCode = CkJsonObject_stringOf(json,"currency.code"); currencySymbol = CkJsonObject_stringOf(json,"currency.symbol"); currencyNative = CkJsonObject_stringOf(json,"currency.native"); currencyPlural = CkJsonObject_stringOf(json,"currency.plural"); time_zoneName = CkJsonObject_stringOf(json,"time_zone.name"); time_zoneAbbr = CkJsonObject_stringOf(json,"time_zone.abbr"); time_zoneOffset = CkJsonObject_stringOf(json,"time_zone.offset"); time_zoneIs_dst = CkJsonObject_BoolOf(json,"time_zone.is_dst"); time_zoneCurrent_time = CkJsonObject_stringOf(json,"time_zone.current_time"); threatIs_tor = CkJsonObject_BoolOf(json,"threat.is_tor"); threatIs_proxy = CkJsonObject_BoolOf(json,"threat.is_proxy"); threatIs_anonymous = CkJsonObject_BoolOf(json,"threat.is_anonymous"); threatIs_known_attacker = CkJsonObject_BoolOf(json,"threat.is_known_attacker"); threatIs_known_abuser = CkJsonObject_BoolOf(json,"threat.is_known_abuser"); threatIs_threat = CkJsonObject_BoolOf(json,"threat.is_threat"); threatIs_bogon = CkJsonObject_BoolOf(json,"threat.is_bogon"); count = CkJsonObject_stringOf(json,"count"); i = 0; count_i = CkJsonObject_SizeOfArray(json,"languages"); while (i < count_i) { CkJsonObject_putI(json,i); name = CkJsonObject_stringOf(json,"languages[i].name"); native = CkJsonObject_stringOf(json,"languages[i].native"); i = i + 1; } CkHttp_Dispose(http); CkJsonObject_Dispose(json); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.