如何用PHP更改我的JSON对象?

时间:2015-09-03 21:37:42

标签: php json

我不知道任何PHP,但我需要让我的JSON对象看起来有某种方式

   $body['aps'] = array(
        'alert' => "look at this stuff",
        'sound' => 'default'
        );
    $payload = json_encode($body);

如何使JSON对象看起来像

{
    "aps": 
    {
        "alert": "look at this stuff",
        "sound": 'default'
    },
    "view": "wc1"
 }

1 个答案:

答案 0 :(得分:4)

您是否尝试在$body中插入另一个值?

$body['aps'] = array(
    'alert' => "look at this stuff",
    'sound' => 'default'
);

$body['view'] = 'wc1';

$payload = json_encode($body);