に変換することはできません私はアンドロイドのスタジオで私のアプリのログインシステムを作るしようとしていると私は、このエラーにJSONException文字列JSONArray
org.json.JSONException得続ける:型のjava.langの価値接続を がJSONArray
に変換することはできませんし、どのような方法でそれを修正することができませんでした.String、私はあなたがそれを発見し、私を助けることができると思います。 はここにここで私は問題があると信じて、ログイン活動の一部(必要であれば、私はより多くのコードを提供することができます)
{StringRequest stringRequest = new StringRequest(Request.Method.POST, login_url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try
{
JSONArray jsonArray = new JSONArray(response);
JSONObject jsonObject = jsonArray.getJSONObject(0);
String code = jsonObject.getString("code");
if(code.equals("login_failed"))
{
builder.setTitle("Login Error...");
displayAlert(jsonObject.getString("message"));
}
else
{
Intent intent = new Intent(LoginActivity.this,TestActivity.class);
Bundle bundle = new Bundle();
bundle.putString("email",jsonObject.getString(("email")));
intent.putExtras(bundle);
startActivity(intent);
}
}
catch (JSONException e)
{
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error)
{
Toast.makeText(LoginActivity.this,"Error",Toast.LENGTH_LONG).show();
error.printStackTrace();
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError
{
Map<String,String> params = new HashMap<String, String>();
params.put("email",email);
params.put("password",password);
return params;
}
};
MySingleton.getmInstance(LoginActivity.this).addToRequestQue(stringRequest);
}
は、PHPのコードです:
<?php
require "connection.php";
$email = $_POST["email"];
$password = $_POST["password"];
$sql = "select email,password from user_info where email like '".$email."' and password like '".$password."';";
$result = mysqli_query($connection,$sql);
$response = array();
if(mysqli_num_rows($result)>0)
{
$row = mysqli_fetch_row($result);
$email = $row[0];
$password = $row[1];
$code = "login_success";
array_push($response,array("code"=>$code,"email"=>$email,"password"=>$password));
echo json_encode($response);
}
else
{
$code = "login_failed";
$message = "User not found...";
array_push($response,array("code"=>$code,"message"=>$message));
echo json_encode($response);
}
mysqli_close($connection);
?>
乾杯メイト、これは、JSON文字列に変換アレイによって解決されました。ありがとうございました –