QRStringJSON.md.txt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # QRStringJSON
  2. [Class `QRStringJSON`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRStringJSON.php):
  3. [JSON](https://developer.mozilla.org/en-US/docs/Glossary/JSON) output.
  4. ## Example
  5. ```php
  6. $options = new QROptions;
  7. $options->outputType = QROutputInterface::STRING_JSON;
  8. $options->jsonFlags = JSON_THROW_ON_ERROR|JSON_UNESCAPED_SLASHES;
  9. header('Content-type: application/json');
  10. $data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
  11. echo (new QRCode($options))->render($data); // -> JSON string
  12. ```
  13. The associated [JSON schema](https://json-schema.org/specification) can be found over at GitHub: [`qrcode.schema.json`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/qrcode.schema.json)
  14. ## Previous functionality
  15. The previous versions of `php-qrcode` (v5 and earlier) just dumped an array representation of the internal matrix,
  16. which is equivalent to the following:
  17. ```php
  18. $matrix = (new QRCode($options))->getQRMatrix(); // -> QRMatrix instance
  19. // retrieve the internal matrix as an array of booleans
  20. $json = json_encode($matrix->getMatrix(true), $jsonFlags);
  21. ```
  22. ## Additional methods
  23. | method | return | description |
  24. |---------------------------------------------------|---------------|-------------------------------------------|
  25. | (protected) `row(int $y, array $row)` | `array\|null` | creates a DOM element for a matrix row |
  26. | (protected) `module(int $x, int $y, int $M_TYPE)` | `array\|null` | creates a DOM element for a single module |
  27. ## Options that affect this class
  28. | property | type |
  29. |--------------|-------|
  30. | `$jsonFlags` | `int` |