注意:数组到字符串转换-json响应与doctrine

时间:2016-05-31 10:03:45

标签: arrays json symfony

我想在数据库中解码之后放一个响应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);
}

0 个答案:

没有答案