首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何输出这个键以数字开头的JSON值?

如何输出这个键以数字开头的JSON值?
EN

Stack Overflow用户
提问于 2012-09-21 07:08:31
回答 2查看 350关注 0票数 1

使用这个json响应:

代码语言:javascript
复制
    {
   "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。我已经非常容易地使用如下命令获取其他所有内容:

代码语言:javascript
复制
$decoded = json_decode($result);
$decoded->votes; //returns # of votes
$decoded->voters->name; //returns the name

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

代码语言:javascript
复制
$decoded->voters->avatarUrls->16x16;
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-21 07:11:51

一如既往。

代码语言:javascript
复制
$decoded->voters->avatarUrls->{'16x16'}
票数 4
EN

Stack Overflow用户

发布于 2012-09-21 07:14:02

你也可以这样做

代码语言:javascript
复制
$decoded = json_decode($result, true);
$decoded['voters']['avatarUrls']['16x16'];

如果您更喜欢Array样式。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12522199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档