I am having a php registration script for android devices which gives me a strange JSON Exception.
{"error":false,"uid":"55fd7bedd4f8a2.33345247","user":{"name":"Theo
Tziomakas","email":"theo@gmail.com","created_at":"2015-09-19
18:14:53","updated_at":null}}
org.json.JSONException: Value <br of type java.lang.String cannot be
converted
to JSONObject
I can insert data from the Android phone,but I don't know where that html thing break line is coming from,which messes up my JSON response. There are similar questions all over here,tried the solutions but nothing happened:(
Here is the php script.
<?php
require_once 'include/DB_Functions.php';
$db = new DB_Functions();
// json response array
$response = array("error" => FALSE);
if (isset($_POST['name']) && isset($_POST['email']) &&
isset($_POST['password'])) {
// receiving the post params
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
// check if user is already existed with the same email
if ($db->isUserExisted($email)) {
// user already existed
$response["error"] = TRUE;
$response["error_msg"] = "User already existed with " . $email;
echo json_encode($response);
} else {
// create a new user
$user = $db->storeUser($name, $email, $password);
if ($user) {
// user stored successfully
$response["error"] = FALSE;
$response["uid"] = $user["unique_id"];
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
echo json_encode($response);
} else {
// user failed to store
$response["error"] = TRUE;
$response["error_msg"] = "Unknown error occurred in registration!";
echo json_encode($response);
}
}
} else {
$response["error"] = TRUE;
$response["error_msg"] = "Required parameters (name, email or
password)
is missing!";
echo json_encode($response);
}
?>
In my json response I get html tags as well!!!
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1'
cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span
style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( !
)</span> Notice: Undefined index: updated_at in
C:\wamp\www\android_login_api\register.php on line <i>34</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left'
bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th>
<th align='left' bgcolor=''>Function</th><th align='left'
bgcolor='c'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec'
align='center'>0.0008</td><td bgcolor='#eeeeec' align='right'>249992</td>
<td bgcolor='#eeeeec'>{main}( )</td><td
title='C:\wamp\www\android_login_api\register.php'
bgcolor='#eeeeec'>..\register.php<b>:</b>0</td></tr>
</table></font>
{"error":false,"uid":"...","user":
{"name":"Theo","email":"theo@gmail.com","created_at":"2015-09-19
19:55:05","updated_at":""}}
In other words I want to remove this.
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1'
cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span
style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>(
!
)</span> Notice: Undefined index: updated_at in
C:\wamp\www\android_login_api\register.php on line <i>34</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left'
bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th>
<th align='left' bgcolor=''>Function</th><th align='left'
bgcolor='c'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec'
align='center'>0.0008</td><td bgcolor='#eeeeec' align='right'>249992</td>
<td bgcolor='#eeeeec'>{main}( )</td><td
title='C:\wamp\www\android_login_api\register.php'
bgcolor='#eeeeec'>..\register.php<b>:</b>0</td></tr>
</table></font>
SOME PROGRESS
I removed the update_at field from the database which was null. I don't get those funny html tags in the JSON response. But still a weird symbol still exists.
{"error":false,"uid":"55fd9bfbdda209.31523184","user":{"name":"Theo Tziomakas","email":"theoaristi53@gmail.com","created_at":"2015-09-19 20:31:39"}}
Do you see the

Finally fixed
The last step I had to was go in the notepad++ and chose encode to ANSI. So at last I get the JSON I want after 9 hours!!! Php can be such a mess. I really want to learn Java EE,but I have no time:(.