1

Take this json response:

    {
   "self":"http://macpro.local:2990/jira/rest/api/2/issue/CSS-4/votes",
   "votes":2,
   "hasVoted":true,
   "voters":[
      {
         "self":"http://macpro.local:2990/jira/rest/api/2/user?username=admin",
         "name":"admin",
         "avatarUrls":{
            "16x16":"http://macpro.local:2990/jira/secure/useravatar?size=small&avatarId=10062",
            "48x48":"http://macpro.local:2990/jira/secure/useravatar?avatarId=10062"
         },
         "displayName":"admin",
         "active":true
      },
      {
         "self":"http://macpro.local:2990/jira/rest/api/2/user?username=timn_1",
         "name":"timn_1",
         "avatarUrls":{
            "16x16":"http://macpro.local:2990/jira/secure/useravatar?size=small&avatarId=10062",
            "48x48":"http://macpro.local:2990/jira/secure/useravatar?avatarId=10062"
         },
         "displayName":"User Two",
         "active":true
      }
   ]
}

I'm at a loss for how to get the avatarUrls->16x16 from above. I've been getting everything else pretty easily with commands like:

$decoded = json_decode($result);
$decoded->votes; //returns # of votes
$decoded->voters->name; //returns the name

But how do I get the 16x16 value? I get an error if I try this:

$decoded->voters->avatarUrls->16x16;
Tim
  • 2,147
  • 4
  • 17
  • 20

2 Answers2

4

Same as always.

$decoded->voters->avatarUrls->{'16x16'}
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
3

You can also do

$decoded = json_decode($result, true);
$decoded['voters']['avatarUrls']['16x16'];

if you like the Array style better.

matt
  • 1,947
  • 1
  • 19
  • 29