0

org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

From what I can gather.. I am receiving a string that is contaminated with HTML and I have no idea why!

I've spent a few hours researching this issue on the internet but have not found any responses that match.

Any advice would be greatly appreciated!

New Logcat response:

   02-29 19:09:05.378 10027-10027/? I/art: Not late-enabling -Xcheck:jni (already on)
02-29 19:09:05.501 10027-10027/k.unionapp W/System: ClassLoader referenced unknown path: /data/app/k.unionapp-2/lib/x86
02-29 19:09:05.888 10027-10027/k.unionapp D/gralloc_goldfish: Emulator without host-side GPU emulation detected.
02-29 19:09:28.450 10027-10413/k.unionapp I/custom_check: The values received in the store part are as follows:
02-29 19:09:28.450 10027-10413/k.unionapp I/custom_check: <br />
                                                          <b>Notice</b>:  Use of undefined constant fname - assumed 'fname' in <b>C:\xampp\htdocs\getuserdata.php</b> on line <b>22</b><br />
                                                          <br />
                                                          <b>Notice</b>:  Use of undefined constant lname - assumed 'lname' in <b>C:\xampp\htdocs\getuserdata.php</b> on line <b>23</b><br />
                                                          <br />
                                                          <b>Notice</b>:  Use of undefined constant email - assumed 'email' in <b>C:\xampp\htdocs\getuserdata.php</b> on line <b>24</b><br />
                                                          <br />
                                                          <b>Notice</b>:  Use of undefined constant password - assumed 'password' in <b>C:\xampp\htdocs\getuserdata.php</b> on line <b>25</b><br />
                                                          <br />
                                                          <b>Notice</b>:  Use of undefined constant fname - assumed 'fname' in <b>C:\xampp\htdocs\getuserdata.php</b> on line <b>22</b><br />
                                                          <br />
                                                          <b>Notice</b>:  Use of undefined constant lname - assumed 'lname' in <b>C:\xampp\htdocs\getuserdata.php</b> on line <b>23</b><br />
                                                          <br />
                                                          <b>Notice</b>:  Use of undefined constant email - assumed 'email' in <b>C:\xampp\htdocs\getuserdata.php</b> on line <b>24</b><br />
                                                          <br />
                                                          <b>Notice</b>:  Use of undefined constant password - assumed 'password' in <b>C:\xampp\htdocs\getuserdata.php</b> on line <b>25</b><br />
                                                          {"fname":"t","lname":"t","email":"t","password":"t"}
02-29 19:09:28.450 10027-10413/k.unionapp W/System.err: org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
02-29 19:09:28.450 10027-10413/k.unionapp W/System.err:     at org.json.JSON.typeMismatch(JSON.java:111)
02-29 19:09:28.450 10027-10413/k.unionapp W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:160)
02-29 19:09:28.450 10027-10413/k.unionapp W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:173)
02-29 19:09:28.450 10027-10413/k.unionapp W/System.err:     at k.unionapp.ServerRequests$getUserDataAsyncTask.doInBackground(ServerRequests.java:89)
02-29 19:09:28.451 10027-10413/k.unionapp W/System.err:     at k.unionapp.ServerRequests$getUserDataAsyncTask.doInBackground(ServerRequests.java:38)
02-29 19:09:28.451 10027-10413/k.unionapp W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:295)
02-29 19:09:28.451 10027-10413/k.unionapp W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-29 19:09:28.451 10027-10413/k.unionapp W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
02-29 19:09:28.451 10027-10413/k.unionapp W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
02-29 19:09:28.451 10027-10413/k.unionapp W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
02-29 19:09:28.451 10027-10413/k.unionapp W/System.err:     at java.lang.Thread.run(Thread.java:818)
02-29 19:09:28.628 10027-10045/k.unionapp W/art: Suspending all threads took: 28.998ms
02-29 19:09:29.103 10027-10027/k.unionapp I/Choreographer: Skipped 42 frames!  The application may be doing too much work on its main thread.

getuserdata.php file:

<?php

$user = "root";
$pass = "";
$db = "uopuser";

$con=mysqli_connect("localhost", $user, $pass, $db) or die("Unable to connect");

$email = $_POST["email"];
$password = $_POST["password"];

$statement = mysqli_prepare($con, "SELECT * FROM User WHERE email = ? AND password = ?");
mysqli_stmt_bind_param($statement, "ss", $email, $password);
mysqli_stmt_execute($statement);

mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $user_id, $fname, $lname, $email, $password);

$user = array();

while(mysqli_stmt_fetch($statement)){
    $user[fname] = $fname;
    $user[lname] = $lname;
    $user[email] = $email;
    $user[password] = $password;
}

echo json_encode($user);

mysqli_stmt_close($statement);

mysqli_close($con);

?>

kmil
  • 243
  • 3
  • 13
  • 1
    your php code likely is producing warnings, and the warning text becomes part of the j output, e.g. `
    Warning: Foo in Bar[json text here]`. capture the raw response, and see what the error is. I'll bet it's something like undefined index warnings, becdause you're sending over `username/password`, but are looking for `email/password`
    – Marc B Feb 29 '16 at 18:56
  • " I am receiving a string that is contaminated with HTML and I have no idea why" - those are php warning messages. `Undefined index: email in C:\xampp\htdocs\getuserdata.php on line 9`. LIne 9 is `$email = $_POST["email"];`, meaning: there was no POST parameter `email` in that request. – VolkerK Feb 29 '16 at 18:57
  • @kmil post your json, instead of server side code – Pragnani Feb 29 '16 at 18:57
  • Please review my new logcat response, Have changed the username mistake pointed out by David Medenjak – kmil Feb 29 '16 at 19:11
  • 1
    I agree with Marc B's decision to close this question. Yet there's so much wrong in the php code, it gives me the hibbie jibbies. Please use http://pastebin.com/kZzuZvza as the basis of your php script. – VolkerK Feb 29 '16 at 19:28

1 Answers1

2

This is an error response, probably paired with a non 200 status code.

You require the email parameter on your server, but you send username. email is not found and the php produces an error.

You should add error handling to your server. To fix your issue either change to username on your server or email in java.

David Medenjak
  • 33,993
  • 14
  • 106
  • 134