关于json的解析有关问题

WBOY
发布: 2016-06-13 12:18:26
原创
895 人浏览过

关于json的解析问题

本帖最后由 u012884755 于 2015-04-14 10:16:22 编辑 $id = $this->input->post('program_id');
$related_change = json_decode($this->input->post('related_change'));
$data = array(
            'user_key'        => $related_change('user_key'),
'channel_id'   => $related_change('channel_id'),
'date'   => $related_change('date'),
'program'         => array(
'name' => $related_change->('program_name'),
'type'        => $related_change('program_type'),
'start_time'  => date('Y-m-d H:i:s', $related_change('program_start_timestamp')),
'end_time'    => date('Y-m-d H:i:s', $related_change('program_end_timestamp')),
'duration'    => (int)$related_change('program_end_timestamp') - (int)$related_change('program_start_timestamp'),
'source_duration' => time_to_sec($related_change('program_original_duration')),
'source_type' => (string)$related_change('src_type'),
'source_start_ts' => $related_change('src_start_time')
 'uri'        => (string)$related_change('program_uri'),  
                                   )
        );



这一块数据是解析的不对的

它们不是从 $thi->input->post 里面出来的, 而是从 $related_change 里面来的

该怎么写?
------解决思路----------------------
$related_change = json_decode($this->input->post('related_change'), true);<br />$data = array(<br />    'user_key'    => $related_change['user_key'],<br />	'channel_id'  => $related_change['channel_id'],<br />	'date'   	  => $related_change['date'],<br />	'program'  => array(<br />		'name' => $related_change['program_name'],<br />		'type'        => $related_change['program_type'],<br />		'start_time'  => date('Y-m-d H:i:s', $related_change['program_start_timestamp']),<br />		'end_time'    => date('Y-m-d H:i:s', $related_change['program_end_timestamp']),<br />		'duration'    => (int)$related_change['program_end_timestamp'] - (int)$related_change['program_start_timestamp'],<br />		'source_duration' => time_to_sec($related_change['program_original_duration']),<br />		'source_type' => (string)$related_change['src_type'],<br />		'source_start_ts' => $related_change['src_start_time'],<br />		'uri'        => (string)$related_change['program_uri'],  <br />    )<br />);
登录后复制

------解决思路----------------------
json_decode() 第二个参数没设置成TRUE的时候是返回对象的,对象应该用 $related_change->user_key 来访问。或者就传入第二个参数为TRUE,以数组形式访问。像3楼那样写。
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板