我制作了 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/