I read some about the error in google , i am bit new to php
org.json.JSONException: Value Record of type java.lang.String cannot be converted to JSONObject
This is my php
$sqlchk="SELECT STATUS FROM OBJECTS WHERE ID=$id";
$res = mysqli_query($con,$sqlchk);
$result = array();
while($row = mysqli_fetch_array($res)){
array_push($result,
array('ID'=>$row[0],
'STATUS'=>$row[1]
));
}
echo json_encode(array("result"=>$result));
this is my code java
try {
try {
responses = client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}
String jsonData = responses.body().string();
JSONObject Jobject = new JSONObject(jsonData);
JSONArray Jarray = Jobject.getJSONArray("result");
if (!responses.isSuccessful()) throw new IOException("Unexpected code " + responses);
for (int i = 0; i < Jarray.length(); i++) {
JSONObject object = Jarray.getJSONObject(i);
String prize = object.getString("STATUS");
System.out.println(prize);
}
} catch (JSONException e) {
Log.e("MYAPP", "unexpected JSON exception", e);
}
catch (Exception e) {
Log.e("MYAPP", "unexpected io exception", e);
}
edit 1
$id= isset($_POST['id']) ? intval($_POST['id']) : null;
$likes= isset($_POST['likes']) ? intval($_POST['likes']) : null;
$conn = mysqli_connect($host,$uname,$pwd,$db) or die(mysqli_error());
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE OBJECTS SET LIKES=$likes where ID=$id ";
if ($conn->query($sql) === TRUE) {
}
$sqlchk="SELECT ID,STATUS FROM OBJECTS WHERE ID=$id";
$res = mysqli_query($conn,$sqlchk);
$result = array();
while($row = mysqli_fetch_array($res)){
array_push($result,
array('ID'=>$row[0],
'STATUS'=>$row[1]
));
}
echo json_encode(array("result"=>$result));
$conn->close();
JSONObject Jobject = new JSONObject(jsonData)and verify what your input string contains? I suspect PHP displays some sort of warning or notice.forloopif (!responses.isSuccessful())should be before you attempt anything with the response data