2

抱歉,如果这是其他人的问题的重复,但在我看来,它似乎与此处的任何其他 PHP 多维数组问题都不匹配。我已经阅读了所有内容。:-(

我正在尝试访问该数组的值(我无法控制)。但它的格式让我感到困惑,但我仍然无法达到我认为应该能够达到的值。

这是我的 JSON 数组示例。

 {"Result":[{"Links":[{"UrlTo":"blahblahA/","Visited":1380104406,"FirstSeen":1375979058,"PrevVisited":1379817016,"Anchor":"text links","Type":"Text","Flag":[],"TextPre":"","TextPost":""}],"Index":0,"Rating":18.44400799929153,"UrlFrom":"blahblahB","IpFrom":"209.18.x.11","Title":"home page","LinksInternal":16,"LinksExternal":5,"Size":13107},{"Links":[{"UrlTo":"blahblahABC","Visited":1380574695,"FirstSeen":1375979100,"PrevVisited":1379224472,"Anchor":"text links","Type":"Text","Flag":[],"TextPre":"","TextPost":""}],"Index":1,"Rating":11.02675617091105,"UrlFrom":"blahblahXYZ","IpFrom":"209.18.x.11","Title":"Random title","LinksInternal":16,"LinksExternal":5,"Size":13107}]}

我天真地以为把这个 Json 数组分配给 $arr 然后像这样解码。

$arr = json_decode($str,true);

一旦完成,我可以像这样引用数组值......

$UrlTo = $arr['Result']['Links']['UrlTo'];

但我显然不理解这一点。我花了很多时间谷歌搜索,阅读,但仍然不明白。我认为这对比我更有经验的人来说是显而易见的吗?有人可以帮助我理解我的方法的幼稚。

4

1 回答 1

5

它的:

$arr['Result'][0]['Links'][0]['UrlTo'];

$arr['Result']是一个数组,原样$arr['Result'][0]['Links']

要获得其他结果,请执行以下操作:

$arr['Result'][1]['Links'][0]['UrlTo'];
于 2013-10-03T15:13:26.863 回答