PureBasic Requires Chilkat v11.7.0+
PureBasic
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 PureBasic Downloads
IncludeFile "CkFormats.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
success.i = 0
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
fmt.i = CkFormats::ckCreate()
If fmt.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
jsonOut.i = CkJsonObject::ckCreate()
If jsonOut.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
i.i
n.i
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateString(json,"target","symbol")
CkJsonObject::ckUpdateString(json,"validation.scope","capacity")
CkJsonObject::ckUpdateString(json,"payload.text","https://www.chilkatsoft.com/barcode_overview.asp")
success = CkFormats::ckQrCode(fmt,"validate",json,jsonOut)
If success = 0
Debug CkFormats::ckLastErrorText(fmt)
CkFormats::ckDispose(fmt)
CkJsonObject::ckDispose(jsonOut)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndIf
Debug "status: " + CkJsonObject::ckStringOf(jsonOut,"validationStatus")
n = CkJsonObject::ckSizeOfArray(jsonOut,"checks")
For i = 0 To n - 1
CkJsonObject::setCkI(jsonOut, i)
Debug " " + CkJsonObject::ckStringOf(jsonOut,"checks[i].name") + ": " + CkJsonObject::ckStringOf(jsonOut,"checks[i].status")
Next
; The same text does not fit version 2 at error-correction level H.
CkJsonObject::ckUpdateInt(json,"encoding.qr.maxVersion",2)
CkJsonObject::ckUpdateString(json,"encoding.qr.errorCorrection","H")
success = CkFormats::ckQrCode(fmt,"validate",json,jsonOut)
If success = 0
Debug CkFormats::ckLastErrorText(fmt)
CkFormats::ckDispose(fmt)
CkJsonObject::ckDispose(jsonOut)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndIf
Debug "status: " + CkJsonObject::ckStringOf(jsonOut,"validationStatus")
n = CkJsonObject::ckSizeOfArray(jsonOut,"checks")
For i = 0 To n - 1
CkJsonObject::setCkI(jsonOut, i)
Debug " " + CkJsonObject::ckStringOf(jsonOut,"checks[i].name") + ": " + CkJsonObject::ckStringOf(jsonOut,"checks[i].status")
Next
n = CkJsonObject::ckSizeOfArray(jsonOut,"findings")
For i = 0 To n - 1
CkJsonObject::setCkI(jsonOut, i)
Debug "finding: " + CkJsonObject::ckStringOf(jsonOut,"findings[i].code") + " at " + CkJsonObject::ckStringOf(jsonOut,"findings[i].path")
Debug " " + CkJsonObject::ckStringOf(jsonOut,"findings[i].message")
Next
; 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
CkFormats::ckDispose(fmt)
CkJsonObject::ckDispose(jsonOut)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure