Pull values from: {"attending":0,"eventid":1,"userid":1} in PHP
<p>So far I've tried a couple of methods for pulling the data from the following array that is received from JAVA(After print_r($_POST)): </p>

<pre><code>{"attending":0,"eventid":1,"userid":1}
</code></pre>

<p>But I am having no luck, as other ways I've found on SO and around the net are all slightly different (Surrounded by ' ' and [])</p>

<p><strong>My code:</strong></p>

<pre><code>print_r($_POST);
$data = json_decode($_POST);

$userid = $data['userid'];
$eventid = $data['eventid'];
$attending = $data['attending'];
</code></pre>

<p>My question is: how do I correctly pull the values from the Post and assign them to values?</p>

<p>I'm new to PHP so please no rude comments.</p>

<p>I have also tried:</p>

<pre><code>$data = json_decode($_POST, true);
</code></pre>

<p>As mentioned in the comments but now I get:</p>

<pre><code>Warning: json_decode() expects parameter 1 to be string, array given in C:\xampp\htdocs\attendanceradio.php on line 9
</code></pre>

<p><strong>var_dump($_POST);:</strong></p>

<pre><code>Array
                                                          (
                                                              [{"attending":0,"eventid":2,"userid":1}] =&gt; 
                                                          )
                                                          array(1) {
                                                            ["{"attending":0,"eventid":2,"userid":1}"]=&gt;
                                                            string(0) ""
                                                          }
</code></pre>

<p><strong>Full PHP code:</strong></p>

<pre><code>&lt;?php

    $user = 'root';
    $pass = '';
    $db = 'testuser';

    $con=mysqli_connect('localhost', $user, $pass, $db) or die('Unable to connect');
    print_r($_POST['json']);
    var_dump($_POST);

    $json = json_decode(trim(key($_POST), '[]'), true);
        var_dump($json);
    $userid = $json['userid'];
    $eventid = $json['eventid'];
    $attending = $json['attending'];

    $statement = mysqli_prepare($con, 
    'INSERT INTO user_has_event(user_user_id, event_event_id, attendance)
        VALUES (?, ?, ?)
        ON DUPLICATE KEY UPDATE attendance = ?');

    mysqli_stmt_bind_param($statement, 'iii', $userid, $eventid, $attending);
    mysqli_stmt_execute($statement);

    mysqli_stmt_store_result($statement);
    mysqli_stmt_bind_result($statement, $userid, $eventid, $attending);

    mysqli_stmt_close($statement);

    mysqli_close($con);
?&gt;
</code></pre>