Hello, I have a problem when I launch the application I have this error displayed in the log of the swift:
Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not have any content around line 2, column 0." UserInfo={NSDebugDescription=JSON text did not have any content around line 2, column 0., NSJSONSerializationErrorIndex=1}
here is the php :
<?php
$hote="myHost";
$login="myLogin";
$mdp="myPassword";
$nomdb="nameDB";
// Create connection
$con= mysqli_connect($hote,$login,$mdp,$nomdb);
$con->set_charset("utf8mb4");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// This SQL statement selects ALL from the table 'Locations'
$sql = "SELECT `id`,`nom`,`prenom`,`tel`,`email`,`mdp`,`adr`,`cp`,`ville` FROM clients";
// Check if there are results
if ($result = mysqli_query($con, $sql))
{
// If so, then create a results array and a temporary one
// to hold the data
$resultArray = array();
$tempArray = array();
// Loop through each row in the result set
while($row = $result->fetch_object())
{
// Add each row into our results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}
// Finally, encode the array to JSON and output the results
echo utf8_encode($resultArray);
}
// Close connections
mysqli_close($con);
?>
With some research I know that this error is due to a json data received from the server (I don't know the exact term sorry)
but unfortunately finding the error and solving it are two different things could help me to solve it ?
To debug this we would need to see the data received from the server before you try to parse it via JSONSerialization
.
Is the line 1 bytes
the output from calling print(data)
? That would definitely not be the valid JSON you are looking for.
Now admittedly I have no experience with PHP, but I must wonder if this line does what the comment says it does:
// Finally, encode the array to JSON and output the results
echo utf8_encode($resultArray);