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) WooCommerce Retrieve a ProductSee more WooCommerce ExamplesDemonstrates how to get the information for a product in JSON format. For more information, see https://woocommerce.github.io/woocommerce-rest-api-docs/#retrieve-a-product
#import <CkoHttp.h> #import <CkoStringBuilder.h> #import <CkoJsonObject.h> #import <CkoDtObj.h> #import <NSString.h> // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkoHttp *http = [[CkoHttp alloc] init]; BOOL success; // Implements the following CURL command: // curl https://example.com/wp-json/wc/v3/products/794 \ // -u consumer_key:consumer_secret // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code http.BasicAuth = YES; http.Login = @"consumer_key"; http.Password = @"consumer_secret"; CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init]; success = [http QuickGetSb: @"https://example.com/wp-json/wc/v3/products/794" sbContent: sbResponseBody]; if (success == NO) { NSLog(@"%@",http.LastErrorText); return; } CkoJsonObject *jResp = [[CkoJsonObject alloc] init]; [jResp LoadSb: sbResponseBody]; jResp.EmitCompact = NO; NSLog(@"%@",@"Response Body:"); NSLog(@"%@",[jResp Emit]); int respStatusCode = [http.LastStatus intValue]; NSLog(@"%@%d",@"Response Status Code = ",respStatusCode); if (respStatusCode >= 400) { NSLog(@"%@",@"Response Header:"); NSLog(@"%@",http.LastHeader); NSLog(@"%@",@"Failed."); return; } // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "id": 794, // "name": "Premium Quality", // "slug": "premium-quality-19", // "permalink": "https://example.com/product/premium-quality-19/", // "date_created": "2017-03-23T17:01:14", // "date_created_gmt": "2017-03-23T20:01:14", // "date_modified": "2017-03-23T17:01:14", // "date_modified_gmt": "2017-03-23T20:01:14", // "type": "simple", // "status": "publish", // "featured": false, // "catalog_visibility": "visible", // "description": "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>\n", // "short_description": "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>\n", // "sku": "", // "price": "21.99", // "regular_price": "21.99", // "sale_price": "", // "date_on_sale_from": null, // "date_on_sale_from_gmt": null, // "date_on_sale_to": null, // "date_on_sale_to_gmt": null, // "price_html": "<span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">$</span>21.99</span>", // "on_sale": false, // "purchasable": true, // "total_sales": 0, // "virtual": false, // "downloadable": false, // "downloads": [ // ], // "download_limit": -1, // "download_expiry": -1, // "external_url": "", // "button_text": "", // "tax_status": "taxable", // "tax_class": "", // "manage_stock": false, // "stock_quantity": null, // "stock_status": "instock", // "backorders": "no", // "backorders_allowed": false, // "backordered": false, // "sold_individually": false, // "weight": "", // "dimensions": { // "length": "", // "width": "", // "height": "" // }, // "shipping_required": true, // "shipping_taxable": true, // "shipping_class": "", // "shipping_class_id": 0, // "reviews_allowed": true, // "average_rating": "0.00", // "rating_count": 0, // "related_ids": [ // 53, // 40, // 56, // 479, // 99 // ], // "upsell_ids": [ // ], // "cross_sell_ids": [ // ], // "parent_id": 0, // "purchase_note": "", // "categories": [ // { // "id": 9, // "name": "Clothing", // "slug": "clothing" // }, // { // "id": 14, // "name": "T-shirts", // "slug": "t-shirts" // } // ], // "tags": [ // ], // "images": [ // { // "id": 792, // "date_created": "2017-03-23T14:01:13", // "date_created_gmt": "2017-03-23T20:01:13", // "date_modified": "2017-03-23T14:01:13", // "date_modified_gmt": "2017-03-23T20:01:13", // "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", // "name": "", // "alt": "" // }, // { // "id": 793, // "date_created": "2017-03-23T14:01:14", // "date_created_gmt": "2017-03-23T20:01:14", // "date_modified": "2017-03-23T14:01:14", // "date_modified_gmt": "2017-03-23T20:01:14", // "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", // "name": "", // "alt": "" // } // ], // "attributes": [ // ], // "default_attributes": [ // ], // "variations": [ // ], // "grouped_products": [ // ], // "menu_order": 0, // "meta_data": [ // ], // "_links": { // "self": [ // { // "href": "https://example.com/wp-json/wc/v3/products/794" // } // ], // "collection": [ // { // "href": "https://example.com/wp-json/wc/v3/products" // } // ] // } // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON CkoDtObj *date_created = [[CkoDtObj alloc] init]; CkoDtObj *date_created_gmt = [[CkoDtObj alloc] init]; CkoDtObj *date_modified = [[CkoDtObj alloc] init]; CkoDtObj *date_modified_gmt = [[CkoDtObj alloc] init]; CkoDtObj *date_on_sale_from = [[CkoDtObj alloc] init]; CkoDtObj *date_on_sale_from_gmt = [[CkoDtObj alloc] init]; CkoDtObj *date_on_sale_to = [[CkoDtObj alloc] init]; CkoDtObj *date_on_sale_to_gmt = [[CkoDtObj alloc] init]; int intVal; NSString *src = 0; NSString *alt = 0; NSString *href = 0; int id = [[jResp IntOf: @"id"] intValue]; NSString *name = [jResp StringOf: @"name"]; NSString *slug = [jResp StringOf: @"slug"]; NSString *permalink = [jResp StringOf: @"permalink"]; [jResp DtOf: @"date_created" bLocal: NO dt: date_created]; [jResp DtOf: @"date_created_gmt" bLocal: NO dt: date_created_gmt]; [jResp DtOf: @"date_modified" bLocal: NO dt: date_modified]; [jResp DtOf: @"date_modified_gmt" bLocal: NO dt: date_modified_gmt]; NSString *v_type = [jResp StringOf: @"type"]; NSString *status = [jResp StringOf: @"status"]; BOOL featured = [jResp BoolOf: @"featured"]; NSString *catalog_visibility = [jResp StringOf: @"catalog_visibility"]; NSString *description = [jResp StringOf: @"description"]; NSString *short_description = [jResp StringOf: @"short_description"]; NSString *sku = [jResp StringOf: @"sku"]; NSString *price = [jResp StringOf: @"price"]; NSString *regular_price = [jResp StringOf: @"regular_price"]; NSString *sale_price = [jResp StringOf: @"sale_price"]; [jResp DtOf: @"date_on_sale_from" bLocal: NO dt: date_on_sale_from]; [jResp DtOf: @"date_on_sale_from_gmt" bLocal: NO dt: date_on_sale_from_gmt]; [jResp DtOf: @"date_on_sale_to" bLocal: NO dt: date_on_sale_to]; [jResp DtOf: @"date_on_sale_to_gmt" bLocal: NO dt: date_on_sale_to_gmt]; NSString *price_html = [jResp StringOf: @"price_html"]; BOOL on_sale = [jResp BoolOf: @"on_sale"]; BOOL purchasable = [jResp BoolOf: @"purchasable"]; int total_sales = [[jResp IntOf: @"total_sales"] intValue]; BOOL virtual = [jResp BoolOf: @"virtual"]; BOOL downloadable = [jResp BoolOf: @"downloadable"]; int download_limit = [[jResp IntOf: @"download_limit"] intValue]; int download_expiry = [[jResp IntOf: @"download_expiry"] intValue]; NSString *external_url = [jResp StringOf: @"external_url"]; NSString *button_text = [jResp StringOf: @"button_text"]; NSString *tax_status = [jResp StringOf: @"tax_status"]; NSString *tax_class = [jResp StringOf: @"tax_class"]; BOOL manage_stock = [jResp BoolOf: @"manage_stock"]; NSString *stock_quantity = [jResp StringOf: @"stock_quantity"]; NSString *stock_status = [jResp StringOf: @"stock_status"]; NSString *backorders = [jResp StringOf: @"backorders"]; BOOL backorders_allowed = [jResp BoolOf: @"backorders_allowed"]; BOOL backordered = [jResp BoolOf: @"backordered"]; BOOL sold_individually = [jResp BoolOf: @"sold_individually"]; NSString *weight = [jResp StringOf: @"weight"]; NSString *dimensionsLength = [jResp StringOf: @"dimensions.length"]; NSString *dimensionsWidth = [jResp StringOf: @"dimensions.width"]; NSString *dimensionsHeight = [jResp StringOf: @"dimensions.height"]; BOOL shipping_required = [jResp BoolOf: @"shipping_required"]; BOOL shipping_taxable = [jResp BoolOf: @"shipping_taxable"]; NSString *shipping_class = [jResp StringOf: @"shipping_class"]; int shipping_class_id = [[jResp IntOf: @"shipping_class_id"] intValue]; BOOL reviews_allowed = [jResp BoolOf: @"reviews_allowed"]; NSString *average_rating = [jResp StringOf: @"average_rating"]; int rating_count = [[jResp IntOf: @"rating_count"] intValue]; int parent_id = [[jResp IntOf: @"parent_id"] intValue]; NSString *purchase_note = [jResp StringOf: @"purchase_note"]; int menu_order = [[jResp IntOf: @"menu_order"] intValue]; int i = 0; int count_i = [[jResp SizeOfArray: @"downloads"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"related_ids"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; intVal = [[jResp IntOf: @"related_ids[i]"] intValue]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"upsell_ids"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"cross_sell_ids"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"categories"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; id = [[jResp IntOf: @"categories[i].id"] intValue]; name = [jResp StringOf: @"categories[i].name"]; slug = [jResp StringOf: @"categories[i].slug"]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"tags"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"images"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; id = [[jResp IntOf: @"images[i].id"] intValue]; [jResp DtOf: @"images[i].date_created" bLocal: NO dt: date_created]; [jResp DtOf: @"images[i].date_created_gmt" bLocal: NO dt: date_created_gmt]; [jResp DtOf: @"images[i].date_modified" bLocal: NO dt: date_modified]; [jResp DtOf: @"images[i].date_modified_gmt" bLocal: NO dt: date_modified_gmt]; src = [jResp StringOf: @"images[i].src"]; name = [jResp StringOf: @"images[i].name"]; alt = [jResp StringOf: @"images[i].alt"]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"attributes"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"default_attributes"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"variations"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"grouped_products"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"meta_data"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"_links.self"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; href = [jResp StringOf: @"_links.self[i].href"]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"_links.collection"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; href = [jResp StringOf: @"_links.collection[i].href"]; i = i + 1; } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.