Dear Monks
I admit I am quite bad at parsing data. I want to read some information out of json data. Someway I am not getting the information I want. The data is the following.
{ "head": {}, "def": [ { "text": "time", "pos": "noun", "ts": "taɪm", "tr": [ { "text": "tempo", "pos": "noun", "gen": "m", "syn": [ { "text": "volta", "pos": "noun", "gen": "f" }, { "text": "momento", "pos": "noun", "gen": "m" }, { "text": "Time", "pos": "noun", "gen": "m" } ], "mean": [ { "text": "day" }, { "text": "moment" } ] } ] } ] }
First of all, I would like to read "text": "tempo" (i.e. tempo). Furthermore I would like to read also a the other values of "text" inside "syn", being the number of "text" element variable
I am using the following:
my $req = HTTP::Request->new(GET => $uri); my $res = $ua->request($req); if ($res->is_success) { my $json_text= $res->content; my $decoded_json = decode_json( $json_text ); my $result = $decoded_json->{'def'}{'tr'}{'text'};#Here I was suppos +ing to get the first "text" value = tempo }
Unfortunately it fails, as I am evidently interpreting badly the data structure (and a dumper did not help me a lot). Any suggestions?
In reply to json decoding by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |