Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoding a QR code containing a JSON string has extra characters on some devices #571

Closed
manabreak opened this issue Mar 17, 2016 · 10 comments

Comments

@manabreak
Copy link

We're working on a QR code scanner and so far it seems to work nicely. However, we noticed that on some devices, when scanning a valid QR code that contains valid JSON, the string has extraneous characters at the end. These characters appear only when scanning JSON QRs, though; when scanning a QR that contains some other text (e.g. ("Hello, world").

So, for example when scanning a QR code that contains this JSON:

{"foo": "bar"}

The result on Nexus 6P is the same, where as the result with LG G3 is:

{"foo": "bar"}@@@@

(The characters are not actually at-signs; they look like those though. I can't copypaste the actual results at the moment.)

What could cause this?

@srowen
Copy link
Contributor

srowen commented Mar 17, 2016

I'm not clear what you are using to encode or decode, whether it's even related to this project. You haven't given an example of the QR code

@manabreak
Copy link
Author

@srowen My mistake. We are using the ZXing library for scanning QR codes in Android. In essence it's like this:

// Initialization of the MultiFormatReader
Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
Collection<BarcodeFormat> decodeFormats = EnumSet.noneOf(BarcodeFormat.class);
decodeFormats.add(BarcodeFormat.CODE_128);
decodeFormats.add(BarcodeFormat.QR_CODE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, getFormats());
MultiFormatReader reader = new MultiFormatReader();
reader.setHints(hints);

// Decoding a bitmap from the camera
protected void decode(BinaryBitmap bitmap, int width, int height) {
    Result rawResult = reader.decodeWithState(bitmap);
    String retval = rawResult.getText();
    Log.d(TAG, "Scanned: " + retval);
}

The Log.d() line at the end prints the raw string that was in the QR code. Basically if we scan a QR code that contains a JSON string, some devices produce the JSON string with extraneous characters while some don't.

@srowen
Copy link
Contributor

srowen commented Mar 17, 2016

You haven't shown evidence that the decoding is the problem. The QR code probably has the text it says it does, right?

@manabreak
Copy link
Author

@srowen I'm not sure I follow. The output of the decoding varies from device to device when the input and the whole codebase remains the same.

@srowen
Copy link
Contributor

srowen commented Mar 17, 2016

That's a function, likely, of the platform character set and how it renders the chars. The (?) chars mean unprintable. But they really are in the QR code, likely.

@srowen srowen closed this as completed Mar 17, 2016
@manabreak
Copy link
Author

@srowen They are not part of the QR code.

@srowen
Copy link
Contributor

srowen commented Mar 17, 2016

You haven't posted any QR code, so I don't think we know that. It's the most likely explanation. Why not examine the code and encoder first?

@manabreak
Copy link
Author

@srowen You can try any QR code generator and type the JSON I mentioned.

@srowen
Copy link
Contributor

srowen commented Mar 17, 2016

Works OK for me:

https://zxing.org/w/chart?cht=qr&chs=350x350&chld=L&choe=UTF-8&chl=%7B%22foo%22%3A+%22bar%22%7D

http://zxing.org/w/decode?u=https%3A%2F%2Fzxing.org%2Fw%2Fchart%3Fcht%3Dqr%26chs%3D350x350%26chld%3DL%26choe%3DUTF-8%26chl%3D%257B%2522foo%2522%253A%2B%2522bar%2522%257D

It's an issue with your code and how you're constructing text to display, or an issue with your encoder. This project's encoder/decoder appear to be fine.

@karthikrchandran
Copy link

Does Zxing work only in Android? Do we need to conditionally check for other mobile OS's like iOS and Windows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants