Questions about parsing JSON

Source: Internet
Author: User
On the parsing problem of JSON
This post was last edited by u012884755 on 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 ')
The ' uri ' = = (string) $related _change (' Program_uri '),
)
);



This piece of data is wrong to parse.

They're not from the $thi->input->post, but from the $related _change.

How do you write it?
------to solve the idea----------------------
 $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_n Ame '],
' 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 ' and ' = ' $related _change[' src_start_time '],
' uri ' = (string) $related _change[' Program_uri '),
)
);

------to solve the idea----------------------
Json_decode () The second parameter is not set to True when the object is returned, and the object should be accessed using the $related _change->user_key. Or pass in the second argument as true, accessed as an array. Write like the 3 floor.
  • 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.