php - JSON.parse 处的 JSON 输入意外结束

标签 php mysql json angular ionic-framework

我制作了 RESTful mysql 后端,一切都很好除了我的 feteched 查询有问题。我的意思是,当我返回的 json 超过 2 个对象时,它什么也不显示。 我正在使用 ionic3/http。

我的select.php:

$sql = "SELECT * FROM products ORDER BY id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    // output data of each row
     $data = array() ;
    while($row = $result->fetch_assoc()) {
        $data[] = $row;
    }
    echo json_encode($data);
} else {
    echo "0";
}

我的 ionic 服务文件:

getProducts(){
    return this.http.get("http://localhost/api/products/select.php")
    .map(res=>{
      this.checkMe = res;

      if(this.checkMe._body !== "0"){
         return res.json()
      }

    } );
  }

我真的需要你的帮助。 谢谢大家。

最佳答案

你尝试过做..

getProducts(){
    return this.http.get("http://localhost/api/products/select.php")
    .map(res=>{
      this.checkMe = res.json() as any;

      if(this.checkMe._body !== "0"){
         return res.json()
      }

    } );
  }

关于php - JSON.parse 处的 JSON 输入意外结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47358042/

相关文章:

json - 如何使用 RethinkDB 提取/过滤 JSON 中的数组对象

java - Android - 获取 JSONArray 问题

jquery - 从 Facebook Graph API 选择 JSON 中的项目编号

php - 我的自定义 get_the_excerpt() 无法通过 ID 获取摘录

php - window.open向php传递参数并触发pdf创建和查看

php - 向后移动 2 个目录不起作用?

mysql - 如何使用 PHPstorm 连接 Openshift Mysql 数据库?

mysql - 通过 PHPMyAdmin 将 PIPE 分隔格式 txt 导入 MySQL

php - 当 HTML 在 1 行时,如何对 HTML 使用 preg_match_all 正则表达式?

java - 连接 mysql 服务器失败