回波响应php+;json编码

回波响应php+;json编码,php,mysql,json,Php,Mysql,Json,我的问题是,在下面的第一个代码中,它没有在浏览器上显示数据,只是显示一个黑色页面。日志中没有错误 另一件事是,它使用var_dump或print_r显示数据,但是它没有以正确的json格式编码 有没有办法回应这个回答?在第二段代码中,我遵循与第一段代码完全相同的过程,它向我显示了我想要的数据,而无需var_dum或print_r 第一代码 此代码的输出是一个空白页 第二代码 下面的工作正常,并显示数据: <?php /* * Following code will list all

我的问题是,在下面的第一个代码中,它没有在浏览器上显示数据,只是显示一个黑色页面。日志中没有错误

另一件事是,它使用var_dump或print_r显示数据,但是它没有以正确的json格式编码

有没有办法回应这个回答?在第二段代码中,我遵循与第一段代码完全相同的过程,它向我显示了我想要的数据,而无需var_dum或print_r

第一代码

此代码的输出是一个空白页

第二代码 下面的工作正常,并显示数据:

<?php
/*
 * Following code will list all the products
 */
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/conectaDB.php';
// connecting to db
$db = new DB_CONNECT();
// check for post data
if (isset($_POST["id"])) {
    $id = $_POST['id'];
    // get all products from products table
    $result = mysql_query("SELECT id, id_estab, dt, hr, quantidade FROM lin_doc WHERE id_cab_doc = $id") or die(mysql_error());
    // check for empty result
    if (mysql_num_rows($result) > 0) {
        // looping through all results
        // products node
        $response["lin_doc"] = array();
        while ($row = mysql_fetch_array($result)) {
            //var_dump($row);
            // temp user array
            $linha               = array();
            $linha["id"]         = $row["id"];
            $linha["id_estab"]   = $row["id_estab"];
            $linha["dt"]         = $row["dt"];
            $linha["hr"]         = $row["hr"];
            $linha["quantidade"] = $row["quantidade"];
            // push single product into final response array
            array_push($response["lin_doc"], $linha);
        }
        // success
        $response["success"] = 1;
        // echoing JSON response
        echo json_encode($response);
    } else {
        // no products found
        $response["success"] = 0;
        $response["message"] = "No products found";
        // echo no users JSON
        echo json_encode($response);
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
    // echoing JSON response
    echo json_encode($response);
}
?>

第二个代码的输出:

《林图文件》:[{id:“66”,“id:”estab:”12”,“dt:”2013-03-26”,“hr:”16:30:00”,“quantidade:”373.000“,{id:”148”,“id:”estab:”16”,“dt:”2013-07-08”,“hr:”20:45:00”,“quantidade:”119.000“,{”id:”260”,“id:”id:”2012-09-20“,”hr:”20:00:”quantidade:”324.000“,”id:”275:”33:00”,“quantidade:”2012-07:00“,”quantidade:”“489.000”,“id:”306”,“id:”estab:”25”,“dt:”2012-07-27”,“hr:”20:45:00”,“quantidade:”338.000“,”id:”468”,“id:”estab:”15”,“dt:”2013-04-23”,“hr:”20:45:00”,“quantidade:”263.000“,“,”id:”546”,“id:”id:”dt:”2013-05-22”,“hr:”11:15:00”,“quantidade:”87:00”,“id:”2013-03”,“quantidade:”263:00“:”3.30.000{“id”:“993”,“id_estab”:“10”,“dt”:“2013-02-03”,“hr”:“19:30:00”,“quantidade”:“441.000”}, “成功”:1}


在连接中:mysql\u set\u charset('utf8',$link)

尝试:

我不确定您在这一点上的查询是否正确:

"as qtd from cab_doc cd where cd.id_tipo_doc = 1"
                    ^^^^                         

在第一个例子中,你通过一个名为
DB\u connect
的类连接数据库,但继续使用
mysql\u
-函数,这可能是错误的。不,那是连接到我的数据库。对不起,我没注意到。男人们,我爱你三天了,我一遍又一遍地发布同样的问题,没有ne真的帮了大忙。y是最好的;)
<?php
$link = mysql_connect('db_host', 'db_user', 'db_password');
mysql_set_charset('utf8', $link);
$db_selected = mysql_select_db('your_db', $link);
foreach( $row as $value ) {
    $value = utf8_encode( $value );
}
"as qtd from cab_doc cd where cd.id_tipo_doc = 1"
                    ^^^^