开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 2215|回复: 3
收起左侧

[js/PHP求助] php取已经json_decode的数据

[复制链接]
结帖率:70% (7/10)
发表于 2017-6-13 14:11:31 | 显示全部楼层 |阅读模式   广东省佛山市

下面这一段数据怎么取第一个text的数据呢。。是php取。不是e,
  1. {"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"}]}}}
复制代码


结帖率:0% (0/1)

签到天数: 1 天

发表于 2017-11-27 17:10:18 | 显示全部楼层   四川省成都市
$text=(array)json_decode('需要解密的内容');
然后你要取内容的话,直接:
$text['showapi_res_code'];
$text['showapi_res_error'];
以此类推
这样就行了
回复 支持 反对

使用道具 举报

结帖率:70% (7/10)
 楼主| 发表于 2017-6-17 10:46:21 | 显示全部楼层   广东省佛山市
挥剑い为红颜 发表于 2017-6-17 10:18
不知道你要下标为0的还是下标为1的  所以把下标写进参数了   灵活一些

恩恩。感谢
回复 支持 反对

使用道具 举报

结帖率:60% (12/20)
发表于 2017-6-17 10:18:51 | 显示全部楼层   山东省烟台市
不知道你要下标为0的还是下标为1的  所以把下标写进参数了   灵活一些
  1. <?php
  2. $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"}]}}}';

  3. echo jsonTest($str, 0);

  4. function jsonTest($jsonStr, $offset) {
  5.     $tmp = json_decode($jsonStr, true);
  6.     $tmp = $tmp['showapi_res_body']['pagebean']['contentlist'][$offset]['text'];
  7.     return trim($tmp);
  8. }
复制代码


回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 诚聘英才| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 800073686,邮箱:800073686@b.qq.com
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表