Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中使用Json从Mysql检索mobilenumber_Android_Json_Android Volley - Fatal编程技术网

如何在Android中使用Json从Mysql检索mobilenumber

如何在Android中使用Json从Mysql检索mobilenumber,android,json,android-volley,Android,Json,Android Volley,当用户登录时,我使用JSON从MySQL数据库中检索详细信息(fname、email、bikeno、mobileno)。除手机号码外,所有详细信息均在检索中 我的代码是: progressBar = new ProgressDialog(v.getContext()); progressBar.setCancelable(true); progressBar.setMessage("Logging You in"); progressBar.setProgressStyle(Progress

当用户登录时,我使用
JSON
从MySQL数据库中检索详细信息(fname、email、bikeno、mobileno)。除手机号码外,所有详细信息均在检索中

我的代码是:

progressBar = new ProgressDialog(v.getContext());
progressBar.setCancelable(true);
progressBar.setMessage("Logging You in");
progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressBar.show();
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);
                JSONObject jsonObject1= 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(MainActivity.this, Home.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("email1", jsonObject.getString("email"));
                    bundle.putString("bikeno1", jsonObject.getString("bikeno"));
                    bundle.putString("fname", jsonObject.getString("fname"));
                    bundle.putString("mobileno", jsonObject.getString("mobileno"));
                    intent.putExtras(bundle);

                    startActivity(intent);
                    finish();
                }
            } catch(Exception e){
            }
        }
    }
});
progressBar=newprogressdialog(v.getContext());
progressBar.setCancelable(真);
setMessage(“登录您”);
progressBar.setProgressStyle(ProgressDialog.STYLE_微调器);
progressBar.show();
StringRequest StringRequest=新的StringRequest(Request.Method.POST、login\u url、,
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
试一试{
JSONArray JSONArray=新JSONArray(响应);
JSONObject JSONObject=jsonArray.getJSONObject(0);
JSONObject JSONObject 1=jsonArray.getJSONObject(0);
字符串代码=jsonObject.getString(“代码”);
if(code.equals(“登录失败”)){
builder.setTitle(“登录错误”);
displayAlert(jsonObject.getString(“消息”);
}否则{
意向意向=新意向(MainActivity.this,Home.class);
Bundle=新Bundle();
bundle.putString(“email1”,jsonObject.getString(“email”);
bundle.putString(“bikeno1”,jsonObject.getString(“bikeno”);
bundle.putString(“fname”,jsonObject.getString(“fname”);
bundle.putString(“mobileno”,jsonObject.getString(“mobileno”);
意向。额外支出(捆绑);
星触觉(意向);
完成();
}
}捕获(例外e){
}
}
}
});
我的问题是如何获取手机号码以及如何将该值发送到其他活动?

请查看以下内容: php:

看看这个: php:


你的json回复中是否有手机号码。没有兄弟。当我注释这行“bundle.putString(“mobileno”,jsonObject.getString(“mobileno”);”时,它显示您登录,但不显示日志。然后它可以登录appShow
JSON
中的
response
。粘贴您的JSON响应。共享您的php和JSON响应。。可能你在json响应中没有收到任何手机号码。你在json响应中没有收到手机号码。没有兄弟。当我注释这行“bundle.putString(“mobileno”,jsonObject.getString(“mobileno”);”时,它显示您登录,但不显示日志。然后它可以登录appShow
JSON
中的
response
。粘贴您的JSON响应。共享您的php和JSON响应。。可能是json响应中没有收到任何手机号码
<?php 

$sql = "SELECT * FROM tablename";

require_once('connectionphp.php');

$r = mysqli_query($conn,$sql);

$result1 = array();

while($row = mysqli_fetch_array($r)){
array_push($result1,array(
    'mobilenum'=>$row['mobilenum']
));
}

echo json_encode($result1);
  StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Toast.makeText(Activity.this,response,Toast.LENGTH_LONG).show();


                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(Activity.this,error.toString(),Toast.LENGTH_LONG).show();
                }
            }){
        @Override
        protected Map<String,String> getParams(){
            Map<String,String> params = new HashMap<String , String>();
            params.put(KEY_MOBILE, mobilenum);


            return params;
        }

    };

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}
 Bundle extras = getIntent().getExtras();
    if(extras != null){
        mob= extras.getString("mobileno");
    }