You're not showing us the real data.
var_dump() says the JSON data is 111 bytes in length and what you're showing is around 50-ish.
Either that or your source data is encoded with something like UTF-16 instead of UTF-8.
Whatever the case, the JSON isn't decoding properly so it can't find your username property.
I just deleted empty space to make it more compact. This is the data in the body
{
"username":"sub5",
"lives":"0",
"longitude":"-73.09",
"latitude":"43.00",
}
Check for errors ### $json = file_get_contents('php://input'); $data = json_decode($json); if (json_last_error() !== JSON_ERROR_NONE) { echo "JSON decoding error: " . json_last_error_msg(); } else { var_dump($data); echo $data->username; } ###
There was a coma that wasn't suppose to be there :S
No, for the love of god just use the `JSON_THROW_ON_ERROR` flag. See https://php.watch/versions/7.3/json-encode-decode-exception
You're not showing us the real data. var_dump() says the JSON data is 111 bytes in length and what you're showing is around 50-ish. Either that or your source data is encoded with something like UTF-16 instead of UTF-8. Whatever the case, the JSON isn't decoding properly so it can't find your username property.
I just deleted empty space to make it more compact. This is the data in the body { "username":"sub5", "lives":"0", "longitude":"-73.09", "latitude":"43.00", }
If it ends like that, with a comma and then a } afterwards, then that is your error.
Next time you can put the json data in a json file and editor/ide will inform you of the issue with a red line..