我試圖從這個 JSON 訪問 ID 和 SENT,但對我不起作用。
更新
$json = '{
"response": {
"sent": true,
"message": "Sent to 57304",
"id": "gBEGVzBChXFYAgmcOrfFpGem8qw"
}
}';
json_decode($json);
$id=$json->id;
$sent=$json->sent;
echo "</br> id:".$id."</br>";
echo "</br> sent:".$sent."</br>";
uj5u.com熱心網友回復:
使用phpjson_decode()函式。像這樣:
$json = '{
"response": {
"sent": true,
"message": "Sent to 57304",
"id": "gBEGVzBChXFYAgmcOrfFpGem8qw"
}
}';
$json = json_decode($json, true);
$json = (object) $json['response'];
echo $json->sent; // output: 1
echo $json->id; // output: "gBEGVzBChXFYAgmcOrfFpGem8qw"
1 等價于布林值 true
uj5u.com熱心網友回復:
它有效,JSON物件有兩個標簽,因此您無法直接訪問內部物件。你應該將 json_decode($json) 分配給一個像 $obj=json_decode($json); 這樣的 php 物件。這是作業檔案
<?php
$json = '{
"response": {
"sent": true,
"message": "Sent to 57304",
"id": "gBEGVzBChXFYAgmcOrfFpGem8qw"
}
}';
// convert assign json data into php object
$obj=json_decode($json);
//All the inner key can be access throug 'response' object
$id=$obj->response->id;
$sent=$obj->response->sent;
echo "</br> id:".$id."</br>";
echo "</br> sent:".$sent."</br>";
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/328576.html
上一篇:PostgresNestJSPrisma遷移-資料庫錯誤代碼:23502關系列包含空值
下一篇:JQ搜索正則運算式
