[英]PHP Notice: Trying to get property of non-object
I have following code and I get PHP notices... 我有以下代码,并且得到了PHP的通知...
$tst_msg = json_decode($received_text); //JSON decode
$user_name = $tst_msg->name; //fetching name
$msg = $tst_msg->message;// fetching messages
I get following notices 我收到以下通知
PHP Notice: Undefined offset: 1
PHP注意:未定义的偏移量:1
PHP Notice: Trying to get property of non-object in..PHP注意:试图获取非对象的属性。
$tst_mst
is a array and not an object. $tst_mst
是一个数组,而不是一个对象。 For objects you can use the arrow, for arrays you have to adres the key like $test[key_name]
. 对于对象,您可以使用箭头,对于数组,您必须使用
$test[key_name]
类的键。
print_r($tst_msg);
gives you the output, then use $test_msg['name']
to get the name (if the key in JSON was 'name'). 给您输出,然后使用
$test_msg['name']
获取名称(如果JSON中的键为'name')。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.