-1
這裏是我的問題:com.android.volley.ParseError:org.json.JSONException:值<java.lang.String類型的BR不能轉換到JSONArray
我試圖通過對從服務器獲取數據在Android中的PHP和每當我嘗試做到這一點,我得到這個錯誤:
[com.android.volley.ParseError:org.json.JSONException:值br的類型java.lang.String不能轉換爲JSONArray]
我確定我的代碼是正確的,因爲我試圖使用https://jsonplaceholder.typicode.com/ 的數據,它工作。
我正在使用xampp服務器並使用php進行連接。
這裏是我的Java代碼:
final String url1 = "http://192.168.0.101/deliveryApp/sellerProfile.php";
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(url1, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.v("response is : ", String.valueOf(response));
for (int i = 0 ; i < response.length() ; i++){
try{
JSONObject jsonObject = response.getJSONObject(i);
String tvfirstname = jsonObject.getString("firstname");
String tvlastname = jsonObject.getString("lastname");
String tvphonenumber = jsonObject.getString("email");
String tvemail = jsonObject.getString("phonenumber");
sellername.setText(tvfirstname +" "+ tvlastname);
selleremail.setText(tvemail+" ");
sellerphonenumber.setText(tvphonenumber+" ");
}catch (JSONException e){
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
System.out.println(error);
}
});
requestQueue.add(jsonArrayRequest);
這我的PHP腳本:
<?php
$dbname = "delivery_app";
$username = "root";
$password = "";
$host = "localhost";
$connection=mysqli_connect($host,$username,$password,$dbname);
session_start();
$email = $_SESSION['tempemail'];
//$email = $_POST["email"];
$querySellerProfile = "SELECT * FROM login WHERE email = '$email'";
if($fetchresult = mysqli_query($connection,$querySellerProfile)){
while ($response = mysqli_fetch_array($fetchresult)) {
// echo $response['firstname'];
// echo $response['lastname'];
// echo $response['email'];
// echo $response['phonenumber'];
// echo $response['password'];
$response2[] = $response;
}
echo json_encode($response2);
}else{
die("failed to get profile information");
}
/*
THIS CODE WILL RETRIEVE USER DATILS , AND ITS WORKING PERFECTLY
*/
?>
,並從服務器的響應是:
[
{
"0": "2",
"1": "testfname",
"2": "testlname",
"3": "testemail",
"4": "9650684491",
"5": "5555",
"id": "2",
"firstname": "testfname",
"lastname": "testlname",
"email": "testemail",
"phonenumber": "9650684491",
"password": "5555"
}
]
我用郵差應用檢查我的PHP是否在工作,它確實。
我只是找不到我的代碼的問題。
任何形式的幫助,將不勝感激。
請您詳細說明?? –