[英]Notice: Trying to get property of non-object in C:\xampp\htdocs\ihelploginapi\index.php on line 5
This code was working 2 days before, but now i am getting an error: 该代码在2天前有效,但现在出现错误:
Trying to get property of non-object in C:\\xampp\\htdocs\\ihelploginapi\\index.php on line 4. 尝试在第4行的C:\\ xampp \\ htdocs \\ ihelploginapi \\ index.php中获取非对象的属性。
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. json_decode
没有给您对象。 It gives you an array. 它给你一个数组。 You want to access it as such: 您想这样访问它:
$tag = $obj['tag'];
or to re-write the var names more accurately 或者更准确地重写var名称
$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. json_decode()
的第二个参数告诉它将JSON对象转换为PHP关联数组,而不是PHP对象。 So you need to use $obj['tag']
instead of $obj->tag
. 因此,您需要使用$obj['tag']
而不是$obj->tag
。 Or change the decode line to 或将解码行更改为
$obj = json_decode($json);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.