简体   繁体   中英

Unexpected end of JSON input at JSON.parse

I made my RESTful mysql backend everything is good except that my feteched query has problem.I mean ,it show me nothing when my returned json is more than 2 objects. I'm working with ionic3 / http.

my 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";
}

my service file in 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()
      }

    } );
  }

I realy need your help. Thank you all.

have you tried to do ..

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()
      }

    } );
  }

I had html tag into one of me fields in the MySQL that stops the json_encode() operation.


Thanks you all 👌👍

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM