|
发表于 2017-6-17 10:18:51
|
显示全部楼层
山东省烟台市
不知道你要下标为0的还是下标为1的 所以把下标写进参数了 灵活一些- <?php
- $str = '{"showapi_res_code":0,"showapi_res_error":"","showapi_res_body":{"ret_code":0,"pagebean":{"allPages":243,"contentlist":[{"text":"\n 欠揍的妹纸第二季,这么逗直接掐死算了!\n ","hate":"130","videotime":"0","voicetime":"0","weixin_url":"http://m.budejie.com/detail-25299481.html/","profile_image":"http://wimg.spriteapp.cn/profile/large/2017/05/16/591a9b554467f_mini.jpg","width":"0","voiceuri":"","type":"41","id":"25299481","love":"248","height":"0","video_uri":"http://mvideo.spriteapp.cn/video/2017/0608/5939529bdad54_wpc.mp4","voicelength":"0","name":"吐嚎Video","create_time":"2017-06-11 00:33:03"},{"text":"\n 有一种能力叫做实力坑队友,求司机心理面积…\n ","hate":"56","videotime":"0","voicetime":"0","weixin_url":"http://m.budejie.com/detail-25311337.html/","profile_image":"http://wimg.spriteapp.cn/profile/large/2017/05/26/5927975c2019c_mini.jpg","width":"0","voiceuri":"","type":"41","id":"25311337","love":"260","height":"0","video_uri":"http://mvideo.spriteapp.cn/video/2017/0609/95ce17a8-4d05-11e7-b2aa-1866daeb0df1_wpc.mp4","voicelength":"0","name":"年少滥情不花心","create_time":"2017-06-10 23:38:01"}]}}}';
- echo jsonTest($str, 0);
- function jsonTest($jsonStr, $offset) {
- $tmp = json_decode($jsonStr, true);
- $tmp = $tmp['showapi_res_body']['pagebean']['contentlist'][$offset]['text'];
- return trim($tmp);
- }
复制代码
|
|