1

采取这个 json 响应:

    {
   "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
      }
   ]
}

我不知道如何从上面获取 avatarUrls->16x16。我已经很容易使用以下命令获得其他所有内容:

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

但是如何获得 16x16 的值?如果我尝试这个,我会得到一个错误:

$decoded->voters->avatarUrls->16x16;
4

2 回答 2

4

一直如此。

$decoded->voters->avatarUrls->{'16x16'}
于 2012-09-20T23:11:50.680 回答
3

你也可以做

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

如果您更喜欢 Array 样式。

于 2012-09-20T23:14:02.240 回答