我有以下代码,我收到PHP通知......
$tst_msg = json_decode($received_text); //JSON decode
$user_name = $tst_msg->name; //fetching name
$msg = $tst_msg->message;// fetching messages
我收到以下通知
PHP注意:未定义的偏移量:1
PHP注意:试图获取 非对象的属性..
答案 0 :(得分:0)
$tst_mst
是一个数组,而不是一个对象。
对于可以使用箭头的对象,对于数组,您必须使用$test[key_name]
。
print_r($tst_msg);
为您提供输出,然后使用$test_msg['name']
获取名称(如果JSON中的键是'名称')。
PHP.net页面上有一个教程。