Java 从android中的json获取空字符串

Java 从android中的json获取空字符串,java,php,android,json,Java,Php,Android,Json,因此,当我使用postman(googleapp)向我的web服务器上的php文件发送post方法时,我得到了一个完整的回复,返回了所有正确的信息。但当我尝试在android上做同样的事情时,我每次都会得到[]的响应 @Override protected Profile doInBackground(Void... params) { ArrayList<NameValuePair> dataToSend = new ArrayList<>();

因此,当我使用postman(googleapp)向我的web服务器上的php文件发送post方法时,我得到了一个完整的回复,返回了所有正确的信息。但当我尝试在android上做同样的事情时,我每次都会得到[]的响应

@Override
    protected Profile doInBackground(Void... params) {
        ArrayList<NameValuePair> dataToSend = new ArrayList<>();
        dataToSend.add(new BasicNameValuePair("name", user.name));
        dataToSend.add(new BasicNameValuePair("password", user.password));
        HttpParams httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpParams, CONNECTION_TIMEOUT);
        HttpClient client = new DefaultHttpClient(httpParams);
        HttpPost post = new HttpPost("http://www.secretvoice1.com/getData.php");
        Profile returnUser = null;
        try {

            HttpResponse httpResponse = client.execute(post);
            post.setEntity(new UrlEncodedFormEntity(dataToSend));
            client.execute(post);
            HttpEntity entity = httpResponse.getEntity();
            Log.d("11111:", httpResponse.toString());
            String result = EntityUtils.toString(entity);
            System.out.println(result);
            Log.d("222222", result);
            JSONObject jsonObject = new JSONObject(result);
            if (jsonObject.length() == 0) {
                returnUser = null;
                Log.d("this:", "here");
            } else {

                //String name = jsonObject.getJSONArray("name");
                //String password = jsonObject.getString("password");
                //String email = jsonObject.getString("email");
                returnUser = new Profile(user.name, user.password, user.email);
            }
            catch(Exception e){
                e.printStackTrace();
            }
            return null;
        }
    }
@覆盖
受保护的配置文件doInBackground(无效…参数){
ArrayList dataToSend=新的ArrayList();
添加(新的BasicNameValuePair(“name”,user.name));
添加(新的BasicNameValuePair(“密码”,user.password));
HttpParams HttpParams=新的BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams,连接超时);
HttpConnectionParams.setSoTimeout(httpParams,连接超时);
HttpClient=新的默认HttpClient(httpParams);
HttpPost=新的HttpPost(“http://www.secretvoice1.com/getData.php");
Profile returnUser=null;
试一试{
HttpResponse HttpResponse=client.execute(post);
post.setEntity(新的UrlEncodedFormEntity(dataToSend));
客户。执行(post);
HttpEntity entity=httpResponse.getEntity();
Log.d(“11111:,httpResponse.toString());
字符串结果=EntityUtils.toString(实体);
系统输出打印项次(结果);
日志d(“222222”,结果);
JSONObject JSONObject=新JSONObject(结果);
if(jsonObject.length()=0){
returnUser=null;
Log.d(“此:,“此处”);
}否则{
//字符串名称=jsonObject.getJSONArray(“名称”);
//字符串密码=jsonObject.getString(“密码”);
//String email=jsonObject.getString(“电子邮件”);
returnUser=新配置文件(user.name、user.password、user.email);
}
捕获(例外e){
e、 printStackTrace();
}
返回null;
}
}

您确定发送的是有效的名称和密码吗?因为我在这里用foo/bar进行了测试,结果返回[]@PankajNimgade为什么要询问用户名和密码?我正试图在postman@HanletEscañoAre中检查这一点,你确定你发送的是有效的名称和密码吗?因为我在这里用foo/bar进行了测试,结果返回[]@PankajNimgade为什么要询问用户名和密码?我正试图在postman@HanletEscaño中检查这一点