Maison > développement back-end > tutoriel php > 关于json的解析问题

关于json的解析问题

WBOY
Libérer: 2016-06-23 13:36:10
original
929 Les gens l'ont consulté

$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 里面来的

该怎么写?


回复讨论(解决方案)

你打印 $this->input->post('related_change')这个出来看看啥就知道了。。。。

应该是传过来json串有问题

$related_change = json_decode($this->input->post('related_change'), true);$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'],      ));
Copier après la connexion

json_decode() 第二个参数没设置成TRUE的时候是返回对象的,对象应该用 $related_change->user_key 来访问。或者就传入第二个参数为TRUE,以数组形式访问。像3楼那样写。

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal