Unicode C Requires Chilkat v11.7.0+
Unicode C
Validate a QR Code Request
See more QR Code Examples
Demonstrates the validate operation, which examines a request without producing anything. The scope says how far to look: definition checks the options, capacity also checks that the data fits a QR symbol, and layout also checks the rendered size against the limits. The response has a validationStatus of valid or invalid, a list of checks, and findings[] describing what is wrong. A request that cannot be understood at all, such as one with a misspelled option, still makes the call fail in the usual way.Chilkat Unicode C Downloads
#include <C_CkFormatsW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkFormatsW fmt;
HCkJsonObjectW jsonOut;
int i;
int n;
HCkJsonObjectW json;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
fmt = CkFormatsW_Create();
jsonOut = CkJsonObjectW_Create();
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"target",L"symbol");
CkJsonObjectW_UpdateString(json,L"validation.scope",L"capacity");
CkJsonObjectW_UpdateString(json,L"payload.text",L"https://www.chilkatsoft.com/barcode_overview.asp");
success = CkFormatsW_QrCode(fmt,L"validate",json,jsonOut);
if (success == FALSE) {
wprintf(L"%s\n",CkFormatsW_lastErrorText(fmt));
CkFormatsW_Dispose(fmt);
CkJsonObjectW_Dispose(jsonOut);
CkJsonObjectW_Dispose(json);
return;
}
wprintf(L"status: %s\n",CkJsonObjectW_stringOf(jsonOut,L"validationStatus"));
n = CkJsonObjectW_SizeOfArray(jsonOut,L"checks");
for (i = 0; i <= n - 1; i++) {
CkJsonObjectW_putI(jsonOut,i);
wprintf(L" %s: %s\n",CkJsonObjectW_stringOf(jsonOut,L"checks[i].name"),CkJsonObjectW_stringOf(jsonOut,L"checks[i].status"));
}
// The same text does not fit version 2 at error-correction level H.
CkJsonObjectW_UpdateInt(json,L"encoding.qr.maxVersion",2);
CkJsonObjectW_UpdateString(json,L"encoding.qr.errorCorrection",L"H");
success = CkFormatsW_QrCode(fmt,L"validate",json,jsonOut);
if (success == FALSE) {
wprintf(L"%s\n",CkFormatsW_lastErrorText(fmt));
CkFormatsW_Dispose(fmt);
CkJsonObjectW_Dispose(jsonOut);
CkJsonObjectW_Dispose(json);
return;
}
wprintf(L"status: %s\n",CkJsonObjectW_stringOf(jsonOut,L"validationStatus"));
n = CkJsonObjectW_SizeOfArray(jsonOut,L"checks");
for (i = 0; i <= n - 1; i++) {
CkJsonObjectW_putI(jsonOut,i);
wprintf(L" %s: %s\n",CkJsonObjectW_stringOf(jsonOut,L"checks[i].name"),CkJsonObjectW_stringOf(jsonOut,L"checks[i].status"));
}
n = CkJsonObjectW_SizeOfArray(jsonOut,L"findings");
for (i = 0; i <= n - 1; i++) {
CkJsonObjectW_putI(jsonOut,i);
wprintf(L"finding: %s at %s\n",CkJsonObjectW_stringOf(jsonOut,L"findings[i].code"),CkJsonObjectW_stringOf(jsonOut,L"findings[i].path"));
wprintf(L" %s\n",CkJsonObjectW_stringOf(jsonOut,L"findings[i].message"));
}
// Sample output:
// status: valid
// definition: passed
// capacity: passed
// layout: notApplicable
// status: invalid
// definition: passed
// capacity: failed
// layout: notApplicable
// finding: capacityExceeded at /payload
// the payload does not fit any admitted QR version at the selected error-correction level
CkFormatsW_Dispose(fmt);
CkJsonObjectW_Dispose(jsonOut);
CkJsonObjectW_Dispose(json);
}