0
votes

i have the following structure which is returned in the variable my @json_device = getDeviceId($Session->{id});

the structure that is being displayed is the following

$VAR1 = [{"device_name":"device1","device_id":"device_id1"},{"device_name":"device2","device_id":"device_id2"}]

i am using the following code to iterate through the array refs and get "device_name" and "device_id" values

 for my $aref (@json_device){
        for my $href (@$aref){
            warn $href->{device_name};
            warn $href->{device_uuid};
        }
    }

but i am getting the following eror Can't use string ("[{"device_name":"iPhone Simulato"...) as an ARRAY ref while "strict refs" in use can anyone explain to me what is going wrong?

1

1 Answers

7
votes

It seems getDeviceId doesn't return Perl data but JSON strings. You have to convert it:

use JSON;

# ..
my $json_device = getDeviceId($Session->{id});
my $aref        = decode_json($json_device);