GettingStarted
GettingStarted

Reputation: 7625

How can I change my JSON object with PHP?

I don't know any PHP but i need to get my JSON object to look a certain way

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

How can I make the JSON object look like

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

Upvotes: 0

Views: 33

Answers (1)

jwueller
jwueller

Reputation: 31006

Are you trying to insert another value into $body?

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

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

$payload = json_encode($body);

Upvotes: 4

Related Questions