我有问题将此字符串解码为数组
$json_array = json_decode($_POST['time_array'],true);
for ($i = 0; $i < count($json_array); $i++)
{
$day = $json_array->day;
$start_time = $json_array->start_time;
$end_time = $json_array->end_time;
$insert_time="INSERT INTO `nesbaty_working_time` (`provider_id`,
`day`,
`opening_time`,
`closing_time`,
`time`,
`status`)
VALUES ('".$provider_id."',
'".$day."',
'".$start_time."',
'".$end_time."',
'".$date."',
'".$status."')";
MysqLi_query($con, $insert_time);
}
Trying to get property of non-object
我的数组字符串是
[{"day":"Monday","start_time":"12 : 00 PM","end_time":"12 : 30 PM"},{"day":"Tuesday","start_time":"12 : 00 PM","end_time":"12 : 30 PM"}]
解决方法:
如果你想要对象类型返回,那么从json_decode中删除true就像
$json_array = json_decode($_POST['time_array']);
并使用索引来访问您返回的数据,如
$day = $json_array[$i]->day;
$start_time = $json_array[$i]->start_time;
$end_time = $json_array[$i]->end_time;