![]()  | 
  
Chilkat  HOME  Android™  AutoIt  C  C#  C++  Chilkat2-Python  CkPython  Classic ASP  DataFlex  Delphi DLL  Go  Java  Node.js  Objective-C  PHP Extension  Perl  PowerBuilder  PowerShell  PureBasic  Ruby  SQL Server  Swift  Tcl  Unicode C  Unicode C++  VB.NET  VBScript  Visual Basic 6.0  Visual FoxPro  Xojo Plugin
 
      (Unicode C) POST JSON to REST API with non-us-ascii Chars EscapedSee more REST ExamplesDemonstrates how to POST to a REST API with non-usascii chars within JSON Unicode escaped.Note: This example requires Chilkat v11.1.0 or greater. 
 #include <C_CkRestW.h> #include <C_CkJsonObjectW.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { BOOL success; HCkRestW rest; BOOL bAutoReconnect; HCkJsonObjectW json; HCkStringBuilderW sb; HCkStringBuilderW sbResp; success = FALSE; success = FALSE; rest = CkRestW_Create(); // Connect using TLS. bAutoReconnect = TRUE; success = CkRestW_Connect(rest,L"chilkatsoft.com",443,TRUE,bAutoReconnect); // Load JSON containing the following Korean text. // { // "BillAddr": { // "Id": "239615", // "Line1": "류리하", // "Line2": "류리하류리하", // "City": "류리하류리하", // "Country": "US", // "CountrySubDivisionCode": "AK", // "PostalCode": "류리하" // } // } json = CkJsonObjectW_Create(); CkJsonObjectW_putEmitCompact(json,FALSE); success = CkJsonObjectW_LoadFile(json,L"qa_data/json/korean.json"); if (success == FALSE) { wprintf(L"%s\n",CkJsonObjectW_lastErrorText(json)); CkRestW_Dispose(rest); CkJsonObjectW_Dispose(json); return; } success = CkRestW_AddHeader(rest,L"Content-Type",L"application/json; charset=UTF-8"); sb = CkStringBuilderW_Create(); CkJsonObjectW_EmitSb(json,sb); CkStringBuilderW_Encode(sb,L"unicodeescape",L"utf-8"); wprintf(L"%s\n",CkStringBuilderW_getAsString(sb)); // The StringBuilder contains this: // { // "BillAddr": { // "Id": "239615", // "Line1": "\ub958\ub9ac\ud558", // "Line2": "\ub958\ub9ac\ud558\ub958\ub9ac\ud558", // "City": "\ub958\ub9ac\ud558\ub958\ub9ac\ud558", // "Country": "US", // "CountrySubDivisionCode": "AK", // "PostalCode": "\ub958\ub9ac\ud558" // } // } sbResp = CkStringBuilderW_Create(); success = CkRestW_FullRequestSb(rest,L"POST",L"/echo_request_body.asp",sb,sbResp); if (success == FALSE) { wprintf(L"%s\n",CkRestW_lastErrorText(rest)); CkRestW_Dispose(rest); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sb); CkStringBuilderW_Dispose(sbResp); return; } // Show the response. wprintf(L"Json Response: %s\n",CkStringBuilderW_getAsString(sbResp)); CkRestW_Dispose(rest); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sb); CkStringBuilderW_Dispose(sbResp); }  | 
  ||||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.