0

私はPHPを使用していて、次のような配列を作成しようとしています。

{
    "aps" : {
        "alert" : "Hey"
    },
    "custom_control" : {
        "type" : "topic_comment",
        "object":{
            "topic_id":"123",
            "topic_section":"test"
                        "plan_id":"456"
        }
    }
}

私が持っているコードは次のとおりです。

 <?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);
?>

しかし、印刷されるのはこれです:

Array ( [aps] => Array ( [alert] => hey ) [custom_control] => Array ( [type] => topic_comment [object] => Array ( [topic_id] => 123 [topic_section] => abc [plan_id] => 456 ) ) )

これは私が意図していたものとはまったく異なるフォーマットのようです。それとも私は何らかの形で間違っていますか?

ありがとう、アレックス

4

2 に答える 2

5

$message変数をjson_encodeするのを忘れたようです。

<?php echo json_encode($message); ?>
于 2013-03-25T22:38:05.077 に答える
1

これを行う必要があります:echo json_encode($message);

print_r($message);配列の内容をダンプし、デバッグに使用します。

于 2013-03-25T22:39:18.557 に答える