on-internet
← Community

PHP API error: "Cannot use object of type stdClass as array" when accessing json_decode result

Stack Overflow ·

I am writing a PHP REST API to allow users to upload content, and I am encountering a Cannot use object of type stdClass as array error. The sign-up part of the API handles input like this without any issue: $f = file_get_contents('php://input'); $jsonobj = stripslashes($f); $obj = json_decode($jsonobj); $email = $obj[0]; $password = $obj[1]; $country = $obj[2]; $city = $obj[3]; $broad = $obj[4]; $type = $obj[5]; $name = $obj[6]; However, the following snippet throws the error: $f = file_get_contents('php://input'); $jsonobj = stripslashes($f); $obj = json_decode($jsonobj); $serviceName = $obj

Comments

Sign in or sign up to comment and upvote.

No comments yet.