PHP的JSON输出麻烦

时间:2018-07-27 13:11:59

标签: php json

我有php这样的代码,可以输出json

<DOCTYPE html>
<html>
<head>
<script>
var stateObj = { nilailumen: "bar" };
history.pushState(stateObj, "page 2", "bar.html");
</script>
</head>
<body>

<?php
require 'koneksi.php';
$STH = $DBH->prepare("SELECT * from nilai_lumen WHERE id =(SELECT MAX(id) from nilai_lumen)");
try{
        $STH->execute();
        $result = array();

        while($row = $STH->fetch(PDO::FETCH_ASSOC)){
                array_push($result, array(
        "lumensatu"=>$row['lumen_satu'],
        "lumendua"=>$row['lumen_dua'],
        "lumentiga"=>$row['lumen_tiga'],
        "lumenempat"=>$row['lumen_empat'],
        "celcius"=>$row['suhu_c'],
        "fahrenhait"=>$row['suhu_f'],
        ));
        }
        echo json_encode(array('result'=>$result));
        $DBH = null;
} catch(PDOException $e){
        echo $e->getMessage();
}
?>
</body>
</html>

我在javascript中有一些脚本,如下所示:

<script>
    var stateObj = { nilailumen: "bar" };
    history.pushState(stateObj, "page 2", "bar.html");
</script>

当我运行此页面时,我得到这样的json

// {"result":[{"lumensatu":"11","lumendua":"10","lumentiga":"8","lumenempat":"10","celcius":"28","fahrenhait":"82"}]}

,我的网址更改为bar.html

为什么我的json中有一些双斜杠以及如何解决?

0 个答案:

没有答案