Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Slim/Userfrosting中设置响应标头_Php_Json_Slim - Fatal编程技术网

Php 在Slim/Userfrosting中设置响应标头

Php 在Slim/Userfrosting中设置响应标头,php,json,slim,Php,Json,Slim,有一个php文件,正在寻找返回json,但不断得到html字符编码错误。。。导航到路线时没有输出 MarkersController.php getMarkersJSON $markers = array(); while ($rows = mysqli_fetch_assoc($result)) { //Assuming "lat" is column name in tester table. Please change it if required. $lat= $rows

有一个php文件,正在寻找返回json,但不断得到html字符编码错误。。。导航到路线时没有输出

MarkersController.php getMarkersJSON

$markers = array();
while ($rows = mysqli_fetch_assoc($result)) {
    //Assuming "lat" is column name in tester table. Please change it if required.
    $lat= $rows['lat'];
    //Assuming "lng" is column name in tester table. Please change it if required.
    $lng= $rows['lng'];

    $markers = array('lat' => $lat, 'lng' => $lng);
}

$app = new \Slim\Slim();
$app->response->headers->set('Content-Type', 'application/json');
echo json_encode($markers);

}
index.php中的路由

$app->get('/markers/', function () use ($app) {
    $controller = new UF\MarkersController($app);
    return $controller->getMarkersJSON();

由于这是一个编码错误,您是否可以尝试将内容类型设置为application/json;字符集=utf-8或尝试从db获取UTF8字符:可能重复