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
(Unicode 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_CkHttpW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkHttpW http; const wchar_t *jsonStr; HCkJsonObjectW json; BOOL success; const wchar_t *ip; BOOL is_eu; const wchar_t *city; const wchar_t *region; const wchar_t *region_code; const wchar_t *country_name; const wchar_t *country_code; const wchar_t *continent_name; const wchar_t *continent_code; const wchar_t *latitude; const wchar_t *longitude; const wchar_t *asn; const wchar_t *organisation; const wchar_t *postal; const wchar_t *calling_code; const wchar_t *flag; const wchar_t *emoji_flag; const wchar_t *emoji_unicode; const wchar_t *currencyName; const wchar_t *currencyCode; const wchar_t *currencySymbol; const wchar_t *currencyNative; const wchar_t *currencyPlural; const wchar_t *time_zoneName; const wchar_t *time_zoneAbbr; const wchar_t *time_zoneOffset; BOOL time_zoneIs_dst; const wchar_t *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 wchar_t *count; int i; int count_i; const wchar_t *name; const wchar_t *native; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); jsonStr = CkHttpW_quickGetStr(http,L"https://api.ipdata.co/149.250.207.170?api-key=MY_API_KEY"); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); return; } json = CkJsonObjectW_Create(); CkJsonObjectW_putEmitCompact(json,FALSE); success = CkJsonObjectW_Load(json,jsonStr); wprintf(L"%s\n",CkJsonObjectW_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 = CkJsonObjectW_stringOf(json,L"ip"); is_eu = CkJsonObjectW_BoolOf(json,L"is_eu"); city = CkJsonObjectW_stringOf(json,L"city"); region = CkJsonObjectW_stringOf(json,L"region"); region_code = CkJsonObjectW_stringOf(json,L"region_code"); country_name = CkJsonObjectW_stringOf(json,L"country_name"); country_code = CkJsonObjectW_stringOf(json,L"country_code"); continent_name = CkJsonObjectW_stringOf(json,L"continent_name"); continent_code = CkJsonObjectW_stringOf(json,L"continent_code"); latitude = CkJsonObjectW_stringOf(json,L"latitude"); longitude = CkJsonObjectW_stringOf(json,L"longitude"); asn = CkJsonObjectW_stringOf(json,L"asn"); organisation = CkJsonObjectW_stringOf(json,L"organisation"); postal = CkJsonObjectW_stringOf(json,L"postal"); calling_code = CkJsonObjectW_stringOf(json,L"calling_code"); flag = CkJsonObjectW_stringOf(json,L"flag"); emoji_flag = CkJsonObjectW_stringOf(json,L"emoji_flag"); emoji_unicode = CkJsonObjectW_stringOf(json,L"emoji_unicode"); currencyName = CkJsonObjectW_stringOf(json,L"currency.name"); currencyCode = CkJsonObjectW_stringOf(json,L"currency.code"); currencySymbol = CkJsonObjectW_stringOf(json,L"currency.symbol"); currencyNative = CkJsonObjectW_stringOf(json,L"currency.native"); currencyPlural = CkJsonObjectW_stringOf(json,L"currency.plural"); time_zoneName = CkJsonObjectW_stringOf(json,L"time_zone.name"); time_zoneAbbr = CkJsonObjectW_stringOf(json,L"time_zone.abbr"); time_zoneOffset = CkJsonObjectW_stringOf(json,L"time_zone.offset"); time_zoneIs_dst = CkJsonObjectW_BoolOf(json,L"time_zone.is_dst"); time_zoneCurrent_time = CkJsonObjectW_stringOf(json,L"time_zone.current_time"); threatIs_tor = CkJsonObjectW_BoolOf(json,L"threat.is_tor"); threatIs_proxy = CkJsonObjectW_BoolOf(json,L"threat.is_proxy"); threatIs_anonymous = CkJsonObjectW_BoolOf(json,L"threat.is_anonymous"); threatIs_known_attacker = CkJsonObjectW_BoolOf(json,L"threat.is_known_attacker"); threatIs_known_abuser = CkJsonObjectW_BoolOf(json,L"threat.is_known_abuser"); threatIs_threat = CkJsonObjectW_BoolOf(json,L"threat.is_threat"); threatIs_bogon = CkJsonObjectW_BoolOf(json,L"threat.is_bogon"); count = CkJsonObjectW_stringOf(json,L"count"); i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"languages"); while (i < count_i) { CkJsonObjectW_putI(json,i); name = CkJsonObjectW_stringOf(json,L"languages[i].name"); native = CkJsonObjectW_stringOf(json,L"languages[i].native"); i = i + 1; } CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.