I want to get my json result from my php and display it in android, I tried many solutions and nothing is working for me. In android side I used JSONParser and always I get json = null in this ligne JSONObject json=jParser.getJSONFromUrl(url);
with this error: Error parsing data org.json.JSONException: Value n of type java.lang.String cannot be converted to JSONObject
I will post my php code because my android code I am sure it is working since I tested it with another php code using codeigniter framework.
function get_user($id = 0) {
global $connection;
$query = "SELECT * FROM users";
if ($id != 0) {
$query. = "WHERE id =".$id. "LIMIT 1";
}
$response = array();
$result = mysqli_query($connection, $query);
while ($row = mysqli_fetch_array($result)) {
array_push($response, array("id" => $row['id'], "username" => $row['username']));
}
header('Content-Type: application/json');
echo json_encode(array('user' => $response));
mysli_close($connection);
}
the result while executing my url is :
{
"user": [
{
"id": "1",
"username": "myusername"
}
]
}