This code was working 2 days before, but now i am getting an error:
Trying to get property of non-object in C:\\xampp\\htdocs\\ihelploginapi\\index.php on line 4.
Somebody please help me out.
<?php
$json = file_get_contents('php://input');
$obj = json_decode($json,TRUE);
$tag = $obj->{'tag'};
?>
json_decode
does not give you an object. It gives you an array. You want to access it as such:
$tag = $obj['tag'];
or to re-write the var names more accurately
$json = file_get_contents('php://input');
$php_array = json_decode($json,TRUE);
$tag = $php_array['tag'];
在相关行中使用:
$tag = $obj['tag'];
The second argument to json_decode()
tells it to convert JSON objects to PHP associative arrays, not PHP objects. So you need to use $obj['tag']
instead of $obj->tag
. Or change the decode line to
$obj = json_decode($json);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.