I am using PHP and trying to create an array that looks something like this:
{
"aps" : {
"alert" : "Hey"
},
"custom_control" : {
"type" : "topic_comment",
"object":{
"topic_id":"123",
"topic_section":"test"
"plan_id":"456"
}
}
}
The code I have is:
<?php
$message = array(
"aps" => array(
"alert" => "hey"
),
"custom_control" => array(
"type" => "topic_comment",
"object" => array(
"topic_id" => "123",
"topic_section" => "abc",
"plan_id" => "456"
)
)
);
print_r($message);
?>
but what is printed out is this:
Array ( [aps] => Array ( [alert] => hey ) [custom_control] => Array ( [type] => topic_comment [object] => Array ( [topic_id] => 123 [topic_section] => abc [plan_id] => 456 ) ) )
It seems like this is a totally different format from what I had intendd. Or am I incorrect in some way?
Thanks, Alex
似乎您忘记了对$ message变量进行json_encode。
<?php echo json_encode($message); ?>
You need to do this: echo json_encode($message);
print_r($message);
just dumps the contents of the array, used it for debugging.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.