Reading and writing JSON in Perl
Errata for JavaScript JSON Cookbook :
use JSON;
use Data::Dumper;
my $json = '{ "call":"KF6GPE","type":"l","time":"1399371514", "lasttime":"1418597513","lat": 37.17667,"lng": -122.14650, "result" : "ok" }';
my %result = decode_json($json);
print Dumper(result);
print encode_json(%result);
Fixed:
use strict;
use warnings;
use JSON;
use Data::Dumper;
# string json
my $json = '{ "call":"KF6GPE","type":"l","time":"1399371514", "lasttime":"1418597513","lat": 37.17667,"lng": -122.14650, "result" : "ok" }';
my $result = decode_json($json);
print Dumper($result);
print encode_json($json), "\n";
Output:
$VAR1 = { 'lat' => '37.17667', 'lasttime' => '1418597513', 'call' => 'KF6GPE', 'time' => '1399371514', 'type' => 'l', 'result' => 'ok', 'lng' => '-122.1465' };
''{\"call\":\"KF6GPE\",\"type\":\"l\",\"time\":\"1399371514\",\n\"lasttime\":\"1418597513\",\"lat\": 37.17667,\"lng\": -122.14650,\n\"result\" : \"ok\" }"
Comments
Post a Comment
Under your writing