[英]PHP error code: Notice: Trying to get property … of non-object in C:\xampp\htdocs\testing\index3.php on line 95
[英]Notice: Trying to get property of non-object in C:\xampp\htdocs\ihelploginapi\index.php on line 5
該代碼在2天前有效,但現在出現錯誤:
嘗試在第4行的C:\\ xampp \\ htdocs \\ ihelploginapi \\ index.php中獲取非對象的屬性。
有人請幫幫我。
<?php
$json = file_get_contents('php://input');
$obj = json_decode($json,TRUE);
$tag = $obj->{'tag'};
?>
json_decode
沒有給您對象。 它給你一個數組。 您想這樣訪問它:
$tag = $obj['tag'];
或者更准確地重寫var名稱
$json = file_get_contents('php://input');
$php_array = json_decode($json,TRUE);
$tag = $php_array['tag'];
在相關行中使用:
$tag = $obj['tag'];
json_decode()
的第二個參數告訴它將JSON對象轉換為PHP關聯數組,而不是PHP對象。 因此,您需要使用$obj['tag']
而不是$obj->tag
。 或將解碼行更改為
$obj = json_decode($json);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.