我想在数据库中解码之后放一个响应json, 我的控制器代码如下:
$jsondata = "{\"employees\":[
{ \"lastName\":\"Doe\"},
{ \"lastName\":\"Smith\"},
{\"lastName\":\"Jones\"}
]}";
$data = json_decode($jsondata, true);
// var_dump($data['employees']);
$machinetags = $data['employees'];
if ($machinetags) {
$machinetags = $em->getRepository('VCycleMachineTagsBundle:MachineTag')->findOrCreateByTitles($machinetags);
}
foreach($machinetags as $machinetag) {
$photo->addMachineTag($machinetag);
}
$em->persist($photo);
$em->flush();
但是当我运行它时,它给了我这个错误:
{
"code": 500,
"message": "An exception occurred while executing 'SELECT t0.id AS id_1, t0.title AS title_2, t0.created_at AS created_at_3 FROM machinetag t0 WHERE t0.title IN (?, ?, ?)' with params [[\"Doe\"], [\"Smith\"], [\"Jones\"]]:\n\nNotice: Array to string conversion"
}
请修复它,例如$ machinetags是一个数组
addMachine函数标记如下:
public function addMachineTag(MachineTag $machinetag)
{
$photoMachineTag = new PhotoMachineTag();
$photoMachineTag->setMachineTag($machinetag);
$photoMachineTag->setPhoto($this);
$this->photoMachineTags->add($photoMachineTag);
}