Dopo il codice perl ho scritto per analizzare un array in JSON. Ma la matrice restituita ha lunghezza 1 e non sono in grado di scorrere correttamente su di essa. Quindi il problema è che non sono in grado di usare l'array restituito.Analisi di un array codificato in JSON tramite perl
#!/usr/bin/perl
use strict;
my $json_text = '[ {"name" : "abc", "text" : "text1"}, {"name" : "xyz", "text" : "text2"} ]';
use JSON;
use Data::Dumper::Names;
my @decoded_json = decode_json($json_text);
print Dumper(@decoded_json), length(@decoded_json), "\n";
L'uscita arriva:
$VAR1 = [
{
'text' => 'text1',
'name' => 'abc'
},
{
'text' => 'text2',
'name' => 'xyz'
}
];
1
Il dereferenziamento aiuta un po '. Ora sono in grado di scorrere l'array restituito. Ma ancora ottengo la lunghezza dell'array = 1 –
Il mio male. Stavo usando la lunghezza (@decoded_json) per ottenere la lunghezza dell'array !! –