In most cases json_encode should be called once only. Keep adding all you want to convert to JSON in a php array, then call json_encode
$json = array('items' => array());
foreach ($items as $item) {
$json['items'][] = array(
'itemName' => $item->name
);
};
echo json_encode($json);
You could also call json_encode for all your $items array without doing a loop
json_encode($items)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…