如何在密钥以数字开头的情况下输出此JSON值? [英] How do I output this JSON value where the key starts with a number?

查看:70
本文介绍了如何在密钥以数字开头的情况下输出此JSON值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行此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.我已经可以使用以下命令轻松获得所有其他信息:

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

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

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

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

推荐答案

一如既往.

$decoded->voters->avatarUrls->{'16x16'}

这篇关于如何在密钥以数字开头的情况下输出此JSON值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆