Json parsing-php Tutorial

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.