Hmm, well, you can't treat a string as a hash or an array as a hash or a hash as an array
You can use eval to trap errors, ref to interrogate values to see what kind of reference they are, or Data::Diver which combines both, Re: Parsing SOAP::Lite results (with Data::Diver) use strict;
use warnings;
use JSON qw/ encode_json decode_json /;
my $json = <<'__JSON__';
{
"fields" : {
"customfield_11872" : [
{
"name" : "0.0.0.0",
"self" : "https://localhost.com:8080/rest/api/2/version/35
+372",
"released" : false,
"id" : "35372",
"archived" : false,
"description" : "Null version. May be deleted after other
+conforming versions are created"
}
]
}
}
__JSON__
my $decoded_json = decode_json( $json );
print $decoded_json->{'fields'}{'customfield_11872'}[0]{'name'}, "\n";
use Data::Diver qw/ Dive /;
if( my $toyArrRef = Dive $decoded_json, qw/ fields customfield_11872 /
+ ){
for my $toy ( @{ $toyArrRef } ){
if( my $name = Dive $toy, qw/ name / ){
print "Name is $name\n";
}
}
}
__END__
0.0.0.0
Name is 0.0.0.0
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|