【问题标题】:Extra character received in a json responsejson 响应中收到的额外字符
【发布时间】:2019-01-02 18:10:54
【问题描述】:

这个 php 文件返回一个 Jason 编码的响应。但我的问题是,除了 Jason 编码器响应之外,它还在响应的前面加上“Here its a picture with the response.
如何删除它?

<?php

        require 'connection.php';

      if (isset($_POST['username']) && !empty($_POST['username']) && isset($_POST['password']) && !empty($_POST['password'])) {


        $username = $_POST["username"];

        $password = $_POST["password"];



        $statement = mysqli_prepare($idCon, "SELECT * FROM user WHERE username = ? AND password = ?");

        mysqli_stmt_bind_param($statement, "ss", $username, $password);

        mysqli_stmt_execute($statement);



        mysqli_stmt_store_result($statement);

        mysqli_stmt_bind_result($statement, $user_ID, $name, $username, $password);



        $response = array();

        $response["success"] = false;  



        while(mysqli_stmt_fetch($statement)){

            $response["success"] = true;  

            $response["name"] = $name;

            $response["username"] = $username;

            $response["password"] = $password;

        }



        echo json_encode($response);
      }
      else{
        $response = array();
            $response["success"] = false;
            echo json_encode($response);
    }
    ?> 

连接 php 文件(我将 $nameUser,$pass,$bazaDeDate 中的日期替换为“***”):

 <?php

        $nameServer="localhost"; 
        $nameUser="******";
        $pass="*****";
        $bazaDeDate="****";

        $idCon=mysqli_connect($nameServer,$nameUser,$pass);
        if(!$idCon)
            die ('Con failed');

        $rezultatSelectBD=mysqli_select_db($idCon,$bazaDeDate);
        if(!$rezultatSelectBD)
            die ('Con failed');


    ?>

【问题讨论】:

  • Trim()、ltrim()、substr()、preg_replace()。您尝试过其中任何一个吗?

标签: php json


【解决方案1】:

检查原始脚本中的 php 开始标签。如果找不到错误,请一一省略部分代码,直到找到留下此“

【讨论】:

    猜你喜欢
    • 2016-08-07
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 2016-05-13
    • 1970-01-01
    • 2015-12-12
    相关资源
    最近更新 更多