I created a php code to seek informations on database (mySQL) and "transform" to JSON.
The JSON output seems to be correct, but when use some validator, alway returns error: Unexpected token
.
If I manually type the JSON output on validator, it works! If I copy and paste, exception occurs.
For verify the JSON: http://devsa.url.ph/?cod=all
<?php
include('connectdb.php');
$something = $_GET['cod'];
$sqlcode = mysql_query("Select descricao from Produtos Where codigo='$something'");
$sqlcode2 = mysql_query("Select descricao from Produtos");
$jsonObj = array();
if ($something == 'all') {
while ($result = mysql_fetch_object($sqlcode2)) {
$jsonObj[] = $result;
}
} else {
while ($result = mysql_fetch_object($sqlcode)) {
$jsonObj[] = $result;
}
}
$final_res = json_encode($jsonObj);
echo $final_res;
?>