kimlid2810 has asked for the wisdom of the Perl Monks concerning the following question:
so here is my problem... i use linux fedora 19. this link contains both english and greek characters. its metatag says:#!/usr/bin/perl use LWP::Simple; # From CPAN use JSON qw( decode_json ); # From CPAN use Data::Dumper; # Perl core module use strict; # Good practice use warnings; # Good practice my $trendsurl = "http://www.somesite.com/"; my $json = get( $trendsurl ); die "Could not get $trendsurl!" unless defined $json; open my $file_write, '>', '/tmp/jsonParser'; print $file_write $json; close($file_write); open my $file_read, '<', '/tmp/jsonParser'; $json = <$file_read>; my $decoded_json = decode_json( $json ); print Dumper $decoded_json;
i downloaded this link with wget and both english and greek characters were readable. i downloaded this link with wget and saved it to a file. the file command for this file returns this:<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
and its characters are readable. the $json variable when printed in screen, prints all the characters as readable. the $json variable when saved to a file like i do above, produces a file with readable characters and this file command response:file: UTF-8 Unicode text, with very long lines, with no line terminato +rs
when i open this file with perl and reassign its contents to the $json variable and print it to screen, all the characters are readable. finally when i decode $json variable the greek characters are transformed to this:file: UTF-8 Unicode text, with very long lines, with no line terminato +rs
the entire response from the site, is json valid, checked with JSONLint. so i must be doing something wrong with the json parser. despite my googling, i couldn't find some hope for a solution. i would welcome any ideas and i would be eternally grateful to anyone providing a possible solution or just a faint hint. thank you :)"\x{3a3}\x{391}\x{39b}\x{3a4}\x{3a3}\x{39c}\x{3a0}\x{39f}\x{3a5}\x{3a1 +}\x{393}\x{39a}"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parsing json, problem with encodings
by Your Mother (Archbishop) on Mar 20, 2014 at 19:01 UTC | |
by kimlid2810 (Acolyte) on Mar 20, 2014 at 19:13 UTC | |
by Your Mother (Archbishop) on Mar 20, 2014 at 19:28 UTC | |
by Laurent_R (Canon) on Mar 20, 2014 at 22:57 UTC |