Reputation: 7387
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();
Upvotes: 0
Views: 194
Reputation: 7106
You need to fix the PHP code first and make sure that it gives you the right JSON string. To verify, try to manually access the php file with the proper POST headers (id and likes).
Upvotes: 1