PHP json_decode error: Array value found, but an object is required -
i trying decode following json file
{ "email": "mail@gmail.com", "password": "12345", "languageproficiency": { "language": "english", "proficiency": 4 }, "tags": [ { "name": "singing" }, { "name": "dance" } ] }
when this
$data = json_decode($jsoncontent, true); echo $data; die();
i have following error:
array value found, object required
question
1) how can view data json 2) how can access property of each object in tags array
i validating json content againsts schema
{ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "email": { "type": "string" }, "password": { "type": "string" }, "languageproficiency": { "type": "object", "properties": { "language": { "type": "string" }, "proficiency": { "type": "integer" } }, "required": [ "language", "proficiency" ] }, "tags": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" } }, "required": [ "name" ] } } }, "required": [ "email", "password", "languageproficiency", "tags" ] }
update
i tried following view json content
print_r($data)
but still same error
$data = json_decode($jsoncontent, true);
above line of code return array, can not use echo directly print array.
to print specific value of array (e.g. email), this:
echo $data["email"];
tip:
use print_r() know array structure this,
echo "<pre>"; print_r($data);
Comments
Post a Comment