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

Unable to decode json with invalid utf8 character #78

Closed
wants to merge 1 commit into from
Closed

Unable to decode json with invalid utf8 character #78

wants to merge 1 commit into from

Conversation

jpty
Copy link

@jpty jpty commented Nov 26, 2021

Change flags parameter of json_decode to ignore invalid utf8
JSON_INVALID_UTF8_IGNORE was added in php 7.2
There is also JSON_INVALID_UTF8_SUBSTITUTE

See also: https://community.jeedom.com/t/unexpected-end-of-json-input/71449/29?u=jpty

Add parameter to ignore invalid utf8 in json_decode
The parameter JSON_INVALID_UTF8_IGNORE was added in php 7.2

See https://community.jeedom.com/t/unexpected-end-of-json-input/71449/29?u=jpty
@jpty
Copy link
Author

jpty commented Nov 26, 2021

If php 5 compatibility is mandatory
The following can be used:

$flagdec = (version_compare(PHP_VERSION, '7.2.0', '>=')) ? JSON_INVALID_UTF8_IGNORE : 0;
$json = json_decode($json_str, true, 512, $flagdec);

@zoic21
Copy link
Contributor

zoic21 commented Jan 28, 2022

Yes php 5 is mandatory for now....

@jpty
Copy link
Author

jpty commented Jan 28, 2022

J'ai testé la proposition de mon commentaire au dessus avec Jeedom v3, sur stretch et php 7.0.
Le flag JSON_INVALID_UTF8_IGNORE est apparu avec php 7.2
J'ai essayé de reculer encore plus avec Jessie. C'est aussi du php 7.0
Qui a encore du php 5 ?

Il n'y a pas d'erreur php dûe à la présence de ce flag inconnu. Le json n'est juste pas décodé.
Pour tout ceux qui auront php 7.2 minimum, le json sera correctement décodé.

Faut-il que je vous refasse une PR ? J'ai détruit mon fork.

@jpty jpty closed this Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants