请问如何将数组转换为JSON格式, 我试过使用以下方法,但没有这样做,任何想法?
这是我目前的结果:
["B型肝炎疫苗下一個注射期为2017-06-30 ","96709394"]
["疫苗名稱4下一個注射期为2017-06-30 ","96709394"]
我想要的是什么:
{"B型肝炎疫苗下一個注射期为2017-06-30 ","96709394"},
{"疫苗名稱4下一個注射期为2017-06-30 ","96709394"}
谢谢
while($row = mysql_fetch_array( $result )) {
echo "<tr>";
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['patientid'] . '</td>';
echo '<td>' . $row['vaccineid'] . '</td>';
echo '<td>' . $row['vaccinename1'] . '</td>';
echo '<td>' . $row['totalnoofinjection'] . '</td>';
echo '<td>' . $row['nthinjection'] . '</td>';
echo '<td>' . $row['date'] . '</td>';
echo '<td>' . $row['nextdate'] . '</td>';
echo '<td>' . $row['skip'] . '</td>';
echo '<td>' . $row['traditionalmessage'] ."<br />";
echo '<td>' . $row['traditionalmessage'] . '</td>';
echo '<td>' . $row['telMobile'] . '</td>';
$data_array = [$row['traditionalmessage'],$row['telMobile']];
foreach($data_array as $key => $value){
$new_data_array[urlencode($key)] = urlencode($value);
}
$data_json_url = json_encode($new_data_array);
$data_json = urldecode($data_json_url);
echo $data_json;