About json parsing problems this post was last edited by u012884755 at 2015-04-1410: 16: 22 $ id & nbsp; $ this-& gt; input-& gt; post (program_id); $ related_change & nbsp; json_decode ($ th about json parsing
This post was last edited by u012884755 on 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 '),
'Signature' => 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 ')
'URL' => (string) $ related_change ('Program _ uri '),
)
);
This piece of data is incorrectly parsed.
They are not from $ thi-> input-> post, but from $ related_change.
How to write?
------ Solution ----------------------
$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'],
)
);
------ Solution ----------------------
Json_decode () is returned when the second parameter is not set to TRUE. the object should be accessed using $ related_change-> user_key. Alternatively, the second parameter is set to TRUE and is accessed as an array. As written on the third floor.