$obj->songs[0]->bmusic->name, artist => $obj->songs[0]->artists[0]->name, url => $obj->songs[0]->mp3url);echo json_encode($array);?>
json文件大致是这样:
{ songs: [ { starred: false, popularity: 95, starrednum: 0, playednum: 0, dayplays: 0, heartime: 0, mp3url: http://m2.music.126.net/2b980ahtvx18bj_z9mhkxa==/2830142929914115.mp3, rturls: [], status: 1, crbt: null, bmusic: { volumedelta: 0.095421, playtime: 200000, bitrate: 96000, dfsid: 2830142929914115, sr: 44100, name: set fire to the rain, id: 24667967, size: 2436177, extension: mp3 }, rturl: null, position: 2, duration: 200000, alias: [], hmusic: { volumedelta: -0.05, playtime: 200000, bitrate: 320000, dfsid: 2830142929914113, sr: 44100, name: set fire to the rain, id: 24667965, size: 8056892, extension: mp3 }, mmusic: { volumedelta: 0.41, playtime: 200000, bitrate: 160000, dfsid: 2830142929914114, sr: 44100, name: set fire to the rain, id: 24667966, size: 4042394, extension: mp3 }, lmusic: { volumedelta: 0.095421, playtime: 200000, bitrate: 96000, dfsid: 2830142929914115, sr: 44100, name: set fire to the rain, id: 24667967, size: 2436177, extension: mp3 }, album: { songs: [], paid: false, onsale: false, status: 1, tags: , blurpicurl: http://p4.music.126.net/j32cgj_dq-4wpfs4u9sjwa==/2539871860943087.jpg, companyid: 0, pic: 2539871860943087, description: , subtype: null, alias: [], picid: 2539871860943087, briefdesc: , artist: { img1v1id: 0, alias: [], picid: 0, briefdesc: , picurl: http://p4.music.126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg, albumsize: 0, img1v1url: http://p3.music.126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg, trans: , musicsize: 0, name: , id: 0 }, picurl: http://p4.music.126.net/j32cgj_dq-4wpfs4u9sjwa==/2539871860943087.jpg, commentthreadid: r_al_3_1983765, artists: [ { img1v1id: 0, alias: [], picid: 0, briefdesc: , picurl: http://p4.music.126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg, albumsize: 0, img1v1url: http://p3.music.126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg, trans: , musicsize: 0, name: piano tribute players, id: 99094 } ], copyrightid: 0, publishtime: 1321804800000, company: cc entertainment, name: piano tribute to adele, id: 1983765, type: 专辑, size: 14 }, commentthreadid: r_so_4_21515271, artists: [ { img1v1id: 0, alias: [], picid: 0, briefdesc: , picurl: http://p3.music.126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg, albumsize: 0, img1v1url: http://p4.music.126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg, trans: , musicsize: 0, name: piano tribute players, id: 99094 } ], copyrightid: 0, score: 95, fee: 0, mvid: 0, ftype: 0, rtype: 0, rurl: null, copyfrom: , audition: null, ringtone: , disc: , no: 2, name: set fire to the rain, id: 21515271 } ], equalizers: {}, code: 200}
上传到主机页面输出结果:
notice: trying to get property of non-object in on line 6 {name:null,artist:piano tribute players,url:null}
回复内容: 代码如下:
$obj->songs[0]->bmusic->name, artist => $obj->songs[0]->artists[0]->name, url => $obj->songs[0]->mp3url);echo json_encode($array);?>
json文件大致是这样:
{ songs: [ { starred: false, popularity: 95, starrednum: 0, playednum: 0, dayplays: 0, heartime: 0, mp3url: http://m2.music.126.net/2b980ahtvx18bj_z9mhkxa==/2830142929914115.mp3, rturls: [], status: 1, crbt: null, bmusic: { volumedelta: 0.095421, playtime: 200000, bitrate: 96000, dfsid: 2830142929914115, sr: 44100, name: set fire to the rain, id: 24667967, size: 2436177, extension: mp3 }, rturl: null, position: 2, duration: 200000, alias: [], hmusic: { volumedelta: -0.05, playtime: 200000, bitrate: 320000, dfsid: 2830142929914113, sr: 44100, name: set fire to the rain, id: 24667965, size: 8056892, extension: mp3 }, mmusic: { volumedelta: 0.41, playtime: 200000, bitrate: 160000, dfsid: 2830142929914114, sr: 44100, name: set fire to the rain, id: 24667966, size: 4042394, extension: mp3 }, lmusic: { volumedelta: 0.095421, playtime: 200000, bitrate: 96000, dfsid: 2830142929914115, sr: 44100, name: set fire to the rain, id: 24667967, size: 2436177, extension: mp3 }, album: { songs: [], paid: false, onsale: false, status: 1, tags: , blurpicurl: http://p4.music.126.net/j32cgj_dq-4wpfs4u9sjwa==/2539871860943087.jpg, companyid: 0, pic: 2539871860943087, description: , subtype: null, alias: [], picid: 2539871860943087, briefdesc: , artist: { img1v1id: 0, alias: [], picid: 0, briefdesc: , picurl: http://p4.music.126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg, albumsize: 0, img1v1url: http://p3.music.126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg, trans: , musicsize: 0, name: , id: 0 }, picurl: http://p4.music.126.net/j32cgj_dq-4wpfs4u9sjwa==/2539871860943087.jpg, commentthreadid: r_al_3_1983765, artists: [ { img1v1id: 0, alias: [], picid: 0, briefdesc: , picurl: http://p4.music.126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg, albumsize: 0, img1v1url: http://p3.music.126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg, trans: , musicsize: 0, name: piano tribute players, id: 99094 } ], copyrightid: 0, publishtime: 1321804800000, company: cc entertainment, name: piano tribute to adele, id: 1983765, type: 专辑, size: 14 }, commentthreadid: r_so_4_21515271, artists: [ { img1v1id: 0, alias: [], picid: 0, briefdesc: , picurl: http://p3.music.126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg, albumsize: 0, img1v1url: http://p4.music.126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg, trans: , musicsize: 0, name: piano tribute players, id: 99094 } ], copyrightid: 0, score: 95, fee: 0, mvid: 0, ftype: 0, rtype: 0, rurl: null, copyfrom: , audition: null, ringtone: , disc: , no: 2, name: set fire to the rain, id: 21515271 } ], equalizers: {}, code: 200}
上传到主机页面输出结果:
notice: trying to get property of non-object in on line 6 {name:null,artist:piano tribute players,url:null}
json还有两个命令:
json_last_error_msg 这个是获取json的错误消息的。
json_last_error 返回最后发生的错误
你可以尝试使用这两个命令来看一下json_encode出现了什么错误。
记得见过php官网手册上有个写法类似:
$obj->{$music->name}
这种的,不知道有没有关系……
(类似场景我都是用数组的多些,感觉在php里比对象好用些。。。新手包涵~)