我在json的末尾得到了一个额外的[],这给我带来了问题。我试图搜索添加这些[]的原因或位置,但找不到任何内容。
所以我需要的是[{content},{content},{content}],但是我得到了[{content},{content},{content}] []
结果应为:
[{“ botserialnumber”:1,“ name”:“”,“ phone”:null,“血压”:20,“ isbreathing”:null,“ isawake”:null,“ heartrate”:101,“ readPhone “:null,” readBot“:1},{” botserialnumber“:4,” name“:” ar“,” phone“:” 7084“,”血压“:90,” isbreathing“:0:” isawake“: 0,“ heartrate”:90,“ readPhone”:1,“ readBot”:1},{“ botserialnumber”:6,“ name”:“”,“ phone”:null,“血压”:1,“ isbreathing” :null,“ isawake”:null,“ heartrate”:5,“ readPhone”:null,“ readBot”:1}]
但是是:
[{“ botserialnumber”:1,“ name”:“”,“ phone”:null,“血压”:20,“ isbreathing”:null,“ isawake”:null,“ heartrate”:101,“ readPhone “:null,” readBot“:1},{” botserialnumber“:4,” name“:” ar“,” phone“:” 7084“,”血压“:90,” isbreathing“:0:” isawake“: 0,“ heartrate”:90,“ readPhone”:1,“ readBot”:1},{“ botserialnumber”:6,“ name”:“”,“ phone”:null,“血压”:1,“ isbreathing” :null,“ isawake”:null,“ heartrate”:5,“ readPhone”:null,“ readBot”:1}] []
使用的代码:
case 'getdata':
$heroes = array();
$stmt = $conn->prepare("SELECT botserialnumber, name, phone, bloodpressure, isbreathing, isawake, heartrate, readPhone, readBot FROM healers");
$stmt->execute();
$stmt->bind_result($botserialnumber, $namen, $phone, $bloodpressure, $isbreathing, $isawake, $heartrate, $readPhone,$readBot);
while($stmt->fetch()){
//pushing fetched data in an array
$temp = [
'botserialnumber'=>$botserialnumber,
'name'=>$namen,
'phone'=>$phone,
'bloodpressure'=>$bloodpressure,
'isbreathing'=>$isbreathing,
'isawake'=>$isawake,
'heartrate'=>$heartrate,
'readPhone'=>$readPhone,
'readBot'=>$readBot
];
//pushing the array inside the hero array
array_push($heroes, $temp);
}
//displaying the data in json format
echo json_encode($heroes);
break;