mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 18:59:33 +00:00
./contrib/statistics/98_fheminfo2.pm: use JSON encode toJSON() from fhem.pl
git-svn-id: https://svn.fhem.de/fhem/trunk@14350 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
5703fef454
commit
d4d3dc4632
@ -92,7 +92,8 @@ sub _fi2_Count() {
|
||||
}
|
||||
|
||||
sub _fi2_Send() {
|
||||
my $json = _fi2_to_json(\%fhemInfo);
|
||||
# my $json = _fi2_to_json(\%fhemInfo);
|
||||
my $json = toJSON(\%fhemInfo);
|
||||
|
||||
Log3("fheminfo",4,"fheminfo: $json");
|
||||
|
||||
@ -188,22 +189,6 @@ sub _fi2_Div($$) {
|
||||
return (int($p1/$p2), $p1 % $p2);
|
||||
}
|
||||
|
||||
sub _fi2_to_json {
|
||||
my $val = shift;
|
||||
if (not defined $val) {
|
||||
return "null";
|
||||
} elsif (not ref $val) {
|
||||
$val =~ s/([\0-\x1f\"\\])/sprintf "\\u%04x", ord $1/eg;
|
||||
return '"' . $val . '"';
|
||||
} elsif (ref $val eq 'ARRAY') {
|
||||
return '[' . join(',', map _fi2_to_json($_), @$val) . ']';
|
||||
} elsif (ref $val eq 'HASH') {
|
||||
return '{' . join(',', map _fi2_to_json($_) . ":" . _fi2_to_json($val->{$_}), sort keys %$val) . '}';
|
||||
} else {
|
||||
return "Cannot encode $val as JSON!\n";
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
Loading…
Reference in New Issue
Block a user