Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.7.0+

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oFmt
LOCAL oJsonOut
LOCAL i
LOCAL n
LOCAL oJson

nSuccess := 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oFmt := CreateObject("Chilkat.Formats")
oJsonOut := CreateObject("Chilkat.JsonObject")

oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("target", "symbol")
oJson:UpdateString("validation.scope", "capacity")
oJson:UpdateString("payload.text", "https://www.chilkatsoft.com/barcode_overview.asp")

nSuccess := oFmt:QrCode("validate", oJson, oJsonOut)
IF (nSuccess == 0)
    ? oFmt:LastErrorText
    oFmt:destroy()
    oJsonOut:destroy()
    oJson:destroy()
    RETURN
ENDIF

? "status: " + oJsonOut:StringOf("validationStatus")
n := oJsonOut:SizeOfArray("checks")
FOR i := 0 TO n - 1
    oJsonOut:I := i
    ? "  " + oJsonOut:StringOf("checks[i].name") + ": " + oJsonOut:StringOf("checks[i].status")
NEXT

//  The same text does not fit version 2 at error-correction level H.
oJson:UpdateInt("encoding.qr.maxVersion", 2)
oJson:UpdateString("encoding.qr.errorCorrection", "H")

nSuccess := oFmt:QrCode("validate", oJson, oJsonOut)
IF (nSuccess == 0)
    ? oFmt:LastErrorText
    oFmt:destroy()
    oJsonOut:destroy()
    oJson:destroy()
    RETURN
ENDIF

? "status: " + oJsonOut:StringOf("validationStatus")
n := oJsonOut:SizeOfArray("checks")
FOR i := 0 TO n - 1
    oJsonOut:I := i
    ? "  " + oJsonOut:StringOf("checks[i].name") + ": " + oJsonOut:StringOf("checks[i].status")
NEXT
n := oJsonOut:SizeOfArray("findings")
FOR i := 0 TO n - 1
    oJsonOut:I := i
    ? "finding: " + oJsonOut:StringOf("findings[i].code") + " at " + oJsonOut:StringOf("findings[i].path")
    ? "  " + oJsonOut:StringOf("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

oFmt:destroy()
oJsonOut:destroy()
oJson:destroy()