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