mercredi 9 décembre 2015

Why do I get the error that there is garbage at the end of my json when trying to use it with objective c?

I have a PHP script that takes the data from an sqlite database and then converts it to json using the json_encode() function. I am getting the data properly but I do not think that it is in the correct format. Everything works great with one record but when you add another record, I get this error message, Error Domain=NSCocoaErrorDomain Code=3840 "Garbage at end." UserInfo={NSDebugDescription=Garbage at end.}

The URL that has the output is http://ift.tt/1mbi3mb

if (file_exists($fileName)) {

//echo "The file $fileName exsists";

try{
$dbHandle = new PDO('sqlite:/home3/anyinfc1/public_html/beklimo/checkedintrainsDB.sql');

$dbHandle->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);

$result = $dbHandle->query('SELECT *FROM trainscheckedin');


foreach ($dbHandle->query('SELECT * FROM trainscheckedin') as $row) {
    echo json_encode($row);
}

}catch (PDOException $e){
echo 'EXCEPTION: '.$e->getMessage();
}
}else{

echo "The file $fileName does not exist";

}


?>

Any help would be great! I am beating my head off the wall. I am new to this so I may not have the output in the correct format. I know that the format works with one entry, just not more then one

Aucun commentaire:

Enregistrer un commentaire