[英]Receive data in Json in PHP
I am posting data to my script file to receive data. 我将数据发布到我的脚本文件以接收数据。 In my script file, File.php
, I am not able to get the object patient
in the dumped results. 在我的脚本文件File.php
,我无法在转储结果中获取对象patient
。 When i do var_dump($get_patient_info->patient);,
it throws an error saying Object {patient} not found. 当我执行var_dump($get_patient_info->patient);,
它会抛出错误,指出找不到对象{patient} 。
Could i be mapping the data wrongly? 我可以错误地映射数据吗?
PS: Beginner in Laravel PS:Laravel的初学者
SendingData Controller 发送数据控制器
$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 File.php
$get_patient_info = $_POST['patient_info'];
var_dump($get_patient_info);
Results 结果
string(189) "[{"patient":"Mohammed Shammar","number":"34"}]"
You can json_decode and fetch the data as follows, 你可以按如下方式json_decode和获取数据,
$temp = json_decode($get_patient_info);
echo $get_patient_info[0]->patient;
json_decode — Decodes a JSON string json_decode - 解码JSON字符串
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.