volley.parsererror: org.json
значение br типа java.lang.string невозможно преобразовать в JSONObject
код Android
public void performSearch() {
String url= "http://192.168.0.136/fyp/stitle.php";
RequestQueue requestQueue = Volley.newRequestQueue(Stitle.this);
JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST,url,null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i("Response", response.toString());
try {
//converting the string to json array object
JSONObject array = new JSONObject();
Log.i("test", " value : " + array.getString("status"));
if (array.getString("status").equals("true")) {
JSONArray jsonArray = array.getJSONArray("search");
Log.i("test", " value : " + array);
for (int i = 0; i < jsonArray.length(); i++) {
//getting product object from json array
JSONObject product = jsonArray.getJSONObject(i);
//adding the product to product list
boolean add = productList.add(new list(
product.getLong("isbn"),
product.getString("title"),
product.getString("authors"),
product.getInt("accession"),
product.getString("publisher"),
product.getInt("pubyear"),
product.getInt("pages"),
product.getInt("rak"),
product.getInt("hr"),
product.getInt("vr"),
product.getLong("barcode")
));
}
} else {
Log.i("test", "else error");
}
} catch (JSONException e) {
e.printStackTrace();
Log.i("test", e.toString());
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "error:" + error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Title", searchtitle.getText().toString());
return params;
}
};
requestQueue = Volley.newRequestQueue(Stitle.this);
requestQueue.add(jsObjRequest);
}
}
Файл кода Php для отправки json в java-файл android
<?php
include"connection.php";
if (isset($title = $_POST["Title"]){
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query =$conn->prepare('SELECT isbn, title, authors, accession, publisher, pubyear, pages, rak, hr, vr, barcode FROM books where title like "%'.$title.'%" ');
$query->execute();
$query->bind_result($isbn, $title, $authors, $accession, $publisher, $pubyear, $pages, $rak, $hr, $vr, $barcode);
$books = array();
$data =array();
//traversing through all the result
while($query->fetch()){
$temp = array();
$temp['isbn'] = $isbn;
$temp['title'] = $title;
$temp['authors'] = $authors;
$temp['accession'] = $accession;
$temp['publisher'] = $publisher;
$temp['pubyear'] = $pubyear;
$temp['pages'] = $pages;
$temp['rak'] = $rak;
$temp['hr'] = $hr;
$temp['vr'] = $vr;
$temp['barcode'] = $barcode;
array_push($data, $temp);
}
$books['status'] = true;
$books['search'] = $data;
//displaying the result in json format
echo json_encode($books);
}}
?>
При запуске приложения эта ошибка отображается на экране [volley.parsererror:org.json.JSONException: значение br типа java.lang.string не может быть преобразовано в JSONArray]