[英]Receive data in Json in PHP
我將數據發布到我的腳本文件以接收數據。 在我的腳本文件File.php
,我無法在轉儲結果中獲取對象patient
。 當我執行var_dump($get_patient_info->patient);,
它會拋出錯誤,指出找不到對象{patient} 。
我可以錯誤地映射數據嗎?
PS:Laravel的初學者
發送數據控制器
$hospitalData = [];
$hospitalData[] = [
'patient' => 'Mohammed Shammar',
'number' => '34',
],
$url = "https://example.com/file.php";
$client = new Client();
$request = $client->post($url, [
'multipart' => [
[
'name' => 'patient_info',
'contents' => json_encode($hospitalData),
],
],
]);
$response = $request->getBody();
return $response;
File.php
$get_patient_info = $_POST['patient_info'];
var_dump($get_patient_info);
結果
string(189) "[{"patient":"Mohammed Shammar","number":"34"}]"
你可以按如下方式json_decode和獲取數據,
$temp = json_decode($get_patient_info);
echo $get_patient_info[0]->patient;
json_decode - 解碼JSON字符串
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.