php不能使用class,php – 致命错误:不能使用stdClass类型的对象作为数组
我知道这可能很简单,我开始明白我需要怎么做,我意识到这与OO有关但是因为我是OO和json的新手我对这个
http://api.discogs.com/database/search?q=d&page=1&per_page=5有点问题它使用json格式的查询d返回5个结果,所以我用php函数解析它,然后尝试让我们说第一个结果显示thubmnail这是我的解析代码:
$returnData = file_get_contents($queryURL);
$discogsJSON = json_decode($returnData);
其中$queryURL =提供的网址.如果我打印$discogsJSON我得到这个:
stdClass Object
(
[pagination] => stdClass Object
(
[per_page] => 5
[items] => 179465
[page] => 1
[urls] => stdClass Object
(
[last] => http://api.discogs.com/database/search?q=f&per_page=5&page=35893
[next] => http://api.discogs.com/database/search?q=f&per_page=5&page=2
)
[pages] => 35893
)
[results] => Array
(
[0] => stdClass Object
(
[style] => Array
(
[0] => Free Jazz
)
[thumb] => http://api.discogs.com/image/R-90-1672955-1305426452.jpeg
[format] => Array
(
[0] => Vinyl
[1] => LP
[2] => Album
)
[country] => Switzerland
[title] => Steve Lacy - Clinkers
[uri] => /Steve-Lacy-Clinkers/master/54331
[label] => Array
(
[0] => Hat Hut Records
)
[catno] => F
[year] => 1978
[genre] => Array
(
[0] => Jazz
)
[resource_url] => http://api.discogs.com/masters/54331
[type] => master
[id] => 54331
)
[1] => stdClass Object
(
[style] => Array
(
[0] => Free Jazz
)
[thumb] => http://api.discogs.com/image/R-90-1672955-1305426452.jpeg
[format] => Array
(
[0] => Vinyl
[1] => LP
[2] => Album
)
[country] => Switzerland
[title] => Steve Lacy - Clinkers
[uri] => /Steve-Lacy-Clinkers/release/1672955
[label] => Array
(
[0] => Hat Hut Records
)
[catno] => F
[year] => 1978
[genre] => Array
(
[0] => Jazz
)
[resource_url] => http://api.discogs.com/releases/1672955
[type] => release
[id] => 1672955
)
[2] => stdClass Object
(
[style] => Array
(
[0] => Alternative Rock
[1] => Goth Rock
[2] => Heavy Metal
)
[thumb] => http://api.discogs.com/image/R-90-2785283-1300918365.jpeg
[format] => Array
(
[0] => CD
[1] => Compilation
[2] => Unofficial Release
)
[country] => Russia
[title] => HIM (2) - Overload Hits
[uri] => /HIM-Overload-Hits/release/2785283
[label] => Array
(
[0] => FullHouse Records
)
[catno] => F?????
[year] => 2003
[genre] => Array
(
[0] => Rock
)
[resource_url] => http://api.discogs.com/releases/2785283
[type] => release
[id] => 2785283
)
[3] => stdClass Object
(
[style] => Array
(
[0] => Drone
[1] => Ambient
)
[thumb] => http://api.discogs.com/image/R-90-3108621-1316178067.jpeg
[format] => Array
(
[0] => CDr
[1] => Album
[2] => Limited Edition
)
[country] => Russia
[title] => Solar Ocean - Twillight October
[uri] => /Solar-Ocean-Twillight-October/release/3108621
[label] => Array
(
[0] => Necrophone
)
[catno] => F
[year] => 2010
[genre] => Array
(
[0] => Electronic
)
[resource_url] => http://api.discogs.com/releases/3108621
[type] => release
[id] => 3108621
)
[4] => stdClass Object
(
[style] => Array
(
[0] => Techno
[1] => Electro
[2] => Tech House
[3] => Minimal
)
[thumb] => http://api.discogs.com/image/R-90-699054-1161976299.jpeg
[format] => Array
(
[0] => Vinyl
[1] => 12"
[2] => Box Set
[3] => Compilation
[4] => Limited Edition
)
[country] => Germany
[title] => Various - Cocoon Compilation F
[uri] => /Various-Cocoon-Compilation-F/master/33655
[label] => Array
(
[0] => Cocoon Recordings
[1] => Cocoon Compilation
)
[catno] => COR LP 011
[year] => 2006
[genre] => Array
(
[0] => Electronic
)
[resource_url] => http://api.discogs.com/masters/33655
[type] => master
[id] => 33655
)
)
)
这是完全正确的,我可以看到我想要的所有数据,但是当我尝试访问(比如说第一个的缩略图)时:
echo $discogsJSON['results']['0']['thumb'];
我留下:致命错误:不能使用stdClass类型的对象作为数组
我想从这里有足够的信息来构建正确的echo语句,但任何人都可以向我解释正确的数据输出背后的OO理论吗?
php不能使用class,php – 致命错误:不能使用stdClass类型的对象作为数组相关推荐
- json_decode到数组
我正在尝试将JSON字符串解码为数组,但出现以下错误. 致命错误:不能在第6行的C:\\ wamp \\ www \\ temp \\ asklaila.php中将stdClass类型的对象用作数组 ...
- php访问object元素,关于object:获取PHP stdObject中的第一个元素
我有一个看起来像这样的对象(存储为$ videos) object(stdClass)#19 (3) { [0]=> object(stdClass)#20 (22) { [" ...
- Java-Jvm-07-深入浅出Jvm浅记
文章目录 1. 走近Java 1.1 概述 1.2 Java的技术体系 1.3 Java的发展史 1.4 Java虚拟机家族 1.4.1 虚拟机始祖:Sun Classic/Exact VM 1.4. ...
- hessiancpp编译和使用(C++版)
个人博客:戳我,戳我 许下的承诺 前两篇博客Hessian通信案例(java)和Hessian源码分析(java)介绍了Java版的hessian的使用以及源码分析.当时也说过打算写一下C++版的he ...
- JVM运行时数据区---方法区(演变和垃圾回收)
方法区演进细节与垃圾回收 方法区演进细节 永久代演进过程: 首先明确:只有 Hotspot 才有永久代.BEA JRockit.IBMJ9 等来说,是不存在永久代的概念的.原则上如何实现方法区属于虚拟 ...
- PHP数组式访问接口ArrayAccess
为什么80%的码农都做不了架构师?>>> PHP数组式访问接口ArrayAccess技术 maybe yes 发表于2015-04-23 22:34 原文链接 : http:/ ...
- 31 道 Java 核心面试题,统统打包给你!
作者 | 沉默王二 来源 | 沉默王二 责编 | 王晓曼 二哥,你好,找工作找了仨月,还没有找到,很焦虑,我该怎么办呢?你那有没有 Java 方面的面试题可以分享一波啊? 以上是读者田田给我发的私信, ...
- PHP基础——语法篇
<!-- 语句:通过 PHP,有两种在浏览器输出文本的基础指令:echo 和 print. --><?php echo "Hello World!"; //PHP ...
- php7.1 改动,PHP7错误处理机制修改
一.现在有两个异常类:Exception and Error. PHP7现在有两个异常类,Exception and Error.这两个类都实现了一个新的接口:Throwable.在您的异常处理代码中 ...
最新文章
- 为什么要继承Serializable类?
- 系列博文-Three.js入门指南(张雯莉)-静态demo和three.js功能概览
- ftpClient的连接超时设置(setConnectTimeout,setSoTimeout)
- linux 多个秘钥,linux管理多个ssh公钥密钥
- python对象的复制问题
- Netty 基本介绍与核心组件(EventLoop、ChannelPipeline、ChannelHandler)
- python学习知识以及就业方向_Python需要学到什么技术 学完可以从事哪些行业
- 一个想法照进现实-《IT连》创业项目:万事开头难
- CentOS安装问题
- OpenCV遍历文件夹中所有图像
- DNS是什么意思?DNS怎么设置?
- 关注虚拟财富“.ME” 域名的投资价值
- M - Help Hanzo(模拟素数筛思想+优化)
- 【Algorithm】GPLT L3-014 球队“食物链”
- 林达华博士对数学的见解
- login.php 什么意思,php is_login()做什么用的;
- 微信小程序实现跑马灯效果(自定义组件详解)
- 虚拟机蓝屏:KMODE EXCEPTION NOT HANDLED
- 通过appt2查看apk包名、versionCode、versionName等
- 成长之路 ------- 一条SQL语句的前世今生
热门文章
- vue项目H5调起高德或百度地图手机应用,或调起高德百度网页版实现导航功能(已实现)
- 【简单】唯一摩尔斯密码词
- 圆周率一千万亿位_圆周率已被算到60万亿位,继续算下去有何意义这里告诉你真正原因...
- SSL证书为什么会有有效期 如何有效避免SSL证书过期
- python copy.deepcopy()深入解读
- 毫无破绽!用这个开源项目换了张脸后,连女朋友都难分真假,能否骗过刷脸支付?...
- win10家庭版打不开组策略的解决方法和彻底关闭病毒和威胁防护
- 微信支付接口,提示:调用支付jsapi缺少参数: $key0$
- 【译文】如何培养自信的习惯(How to Bulid the Confidence Habit)
- 简谈FPGA设计中不同设计方法资源消耗对比