这个php脚本
<?php
require('medoo.min.php');
header('Content-type: application/json');
$database = new medoo('brickx');
$datas = $database->select("customer", ["Companyname", "Phonenumber"]);
$jsonresponse = array("customers"=> array());
array_push($jsonresponse["customers"], $datas);
echo (json_encode($jsonresponse));
?>
输出这种json:
{"customers":[[{"Companyname":"company1","Phonenumber":"+567890789"},{"Companyname":"company2","Phonenumber":"5678905678"}]]}
然而我需要摆脱方括号并得到类似
的东西{"customers":{"Companyname":"company1","Phonenumber":"+567890789"},{"Companyname":"company2","Phonenumber":"5678905678"}}
有什么建议吗?
答案 0 :(得分:1)
$datas
已经是一个数组,你可能想要这个:
$array = array('customers' => $datas);
echo json_encode($array);