I am developing this android app which I send the data on server and then I have to retrieve the data and show them on a chart (anychartLibrary).
I've written this php code which helps me send the date to the server and retrieve the data related to that date, but instead of getting a jsonObject I get this html line, which I have noticed using Postman...
<?php
if ($_SERVER['REQUEST_METHOD']=='POST') {
require_once('init.php');
$myDate =$_GET['myDate'];
$sql =" SELECT * FROM parkinsonism_value WHERE myDate='$myDate' ;";
$result = mysqli_query($connect,$sql);
$row = mysqli_fetch_assoc($result);
if (isset($row)) {
$record['myDate'] = $row['myDate'];
$record['parkinsonism'] = $row['parkinsonism'];
} else {
$record['myDate'] ="";
$record['parkinsonism'] ="";
}
header('Content-type=application/json');
echo json_encode(array("list"=>$record),JSON_UNESCAPED_SLASHES);
}
?>
and this is the volley json Object Request:
public void getString(){
String url = "http://46.4.151.237/StHans/getparkinsonism.php"+"?myDate="+finalDate;
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(getContext(),response.toString(),Toast.LENGTH_SHORT).show();
try {
jsObject =response.getJSONObject("list");
sss =jsObject.getString("parkinsonism");
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getContext(),error.getMessage(),Toast.LENGTH_SHORT).show();
}
});
// Access the RequestQueue through your singleton class.
MySingleton.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
}
by the way about the final date:
calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
finalDate =dayOfMonth +"/"+(month +1)+"/"+ year;
now I have this error which tells me value success of type java.lang.string cannot be converted to JSONOBJECT. what should I change to get this to work? thanks:|