1

this php script

 <?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));

 ?>

outputs this kind of json:

 {"customers":[[{"Companyname":"company1","Phonenumber":"+567890789"},{"Companyname":"company2","Phonenumber":"5678905678"}]]}

however i need to get rid of the square brackets and get something like

{"customers":{"Companyname":"company1","Phonenumber":"+567890789"},{"Companyname":"company2","Phonenumber":"5678905678"}}

any suggestions?

4

1 回答 1

1

$datas已经是一个数组,你可能想要这个:

$array = array('customers' => $datas);
echo json_encode($array);
于 2013-09-24T17:29:48.100 回答