JSON与android不兼容Android设备

时间:2016-01-19 12:20:20

标签: php android json

我遇到JSON登录问题。

这是PHP文件:

SELECT DATENAME(month,MONTH( DATEADD(s, nDateTime, '01/01/1970'))) as [month],YEAR( DATEADD(s, nDateTime, '01/01/1970')) as [year]

机器人:

<?php 
require "init.php";

$UserName =$_POST["User_UserName"];
$Password =md5($_POST["User_Password"]);

$result = mysqli_query($con,"SELECT User_UserName FROM User WHERE User_UserName = '$UserName' and User_Password='$Password'");
$row = mysqli_fetch_array($result);
$data = $row[0];

if($data){
$response["success"] = 1;
         $response["message"] = "You have been sucessfully login";
 $response["UserName"] = $data;
         die(json_encode($response)); 
         }
                 else
                 { 
        $response["success"] = 0; 
         $response["message"] = "invalid username or password ";
         die(json_encode($response));
                } 

         mysql_close(); 
         ?>

它正在使用Android模拟器,但没有使用Genymotion模拟器,也没有使用我的Android设备。

任何解决方案?

这是错误:

RequestQueue requestQueue;

    String LoginURL = "..../login.php";
requestQueue = Volley.newRequestQueue(getApplicationContext());

btLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {




                StringRequest request = new StringRequest(Request.Method.POST, LoginURL, new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonObject = new JSONObject(response);
                            if(jsonObject.names().get(0).equals("success")) {
                                Toast.makeText(getApplicationContext(),"Success "+jsonObject.getString("UserName"),Toast.LENGTH_SHORT).show();
                                Intent intent= new Intent(MainActivity.this,Welcome.class);
                                intent.putExtra("UserName",jsonObject.getString("UserName"));
                                startActivity(intent);
                                // startActivity(new Intent(getApplication(),Welcome.class));
                            }
                            else
                            {
                                Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_SHORT).show();
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                    }
                }){
                    @Override
                    protected Map<String, String> getParams() throws AuthFailureError {
                        Map<String,String> parameters = new HashMap<String, String>();
                        parameters.put("User_UserName",etEmail.getText().toString());
                        parameters.put("User_Password",etPassword.getText().toString());

                        return parameters;
                    }
                };

                requestQueue.add(request);




            }
        });

0 个答案:

没有答案