2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

98_expandJSON.pm: encode JSON with utf8, JSON boolean handling (Forum #82734)

git-svn-id: https://svn.fhem.de/fhem/trunk@16115 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
dev0 2018-02-08 08:20:45 +00:00
parent 096387c596
commit 26b1085471

View File

@ -22,13 +22,14 @@
#
################################################################################
my $module_version = "1.10";
my $module_version = "1.12";
package main;
use strict;
use warnings;
use POSIX;
use Encode;
sub expandJSON_expand($$$$;$$); # Forum #66761
@ -175,7 +176,7 @@ sub expandJSON_decode($$$$) {
my ($name,$type) = ($hash->{NAME},$hash->{TYPE});
my $dhash = $defs{$dname};
my $h;
eval { $h = decode_json($dvalue); 1; };
eval { $h = decode_json(encode_utf8($dvalue)); 1; };
if ( $@ ) {
Log3 $name, 2, "$type $name: Bad JSON: $dname $dreading: $dvalue";
Log3 $name, 2, "$type $name: $@";
@ -218,6 +219,12 @@ sub expandJSON_expand($$$$;$$) {
}
}
}
elsif( ref( $ref ) eq "JSON::PP::Boolean" ) { # Forum #82734
(my $reading = $sPrefix.$prefix) =~ s/[^A-Za-z\d_\.\-\/]/_/g;
$reading = substr($reading, 0, -1); #remove tailing _
readingsBulkUpdate($dhash, $reading, $ref ? 1 : 0)
if $reading =~ m/^$hash->{t_regexp}$/;
}
}