i am trying to write kind of user client server using java(android) and php.i asked this question before but no one answer my question.my database is utf8.i am nearly for two weeks trying to solve the problem of this part but i couldn't. the problem is: I have one array that it contains my database rows and when you use:
print_r ($jasonData);
and give an output from that you can see it's not null but when i use:
echo json_encode($jasonData);
it shows null and i can't understand why it can happens. i've searched in stack before and i saw every related questions.but they didn't work for me. also the
echo json_last_error();
shows 0.
<?php
$hostname = "localhost";
$dbname = "amir";
$dbpass = "123456";
$con = new mysqli($hostname,$dbname,$dbpass,'amir');
$jasonData = array();
$sql="select Username , Password from User_Login ";
if($result = $con->query($sql)){
while($row = $result->fetch_row()){
$jasonData[] = array_map('utf8_encode', $row);
/*
print $row[0];
print $row[1];
*/
}
}
print_r ($jasonData);
echo json_encode($jsonData);
print json_last_error();
$con->close();
If anyone knows why that happens,please give me an advice how can i fix that.