从我的 JSON 解析器获取空指针异常


Getting a null pointer exception from my JSON parser

转换结果 java.lang.NullPointerException 时出错:lock == null解析数据时出错 org.json.JSONException:字符 0 处的输入结束之

<小时 />

谁能告诉我这是否有效??我已经将我的笔记本电脑与我的 wifi 和手机也连接起来了。两者都具有相同的IPv4地址,并且在Android代码中我提到了该地址。我的手机如何知道联系存储数据库的笔记本电脑?

<小时 />

这是我的安卓代码JSON解析器

 public JSONObject makeHttpRequest(String url, String method,List<NameValuePair> params) {
    try {
        if(method.equals("POST"))
        {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            Log.e("herehai"," "+is); 
            HttpPost httpPost = new HttpPost(url);
            Log.e("hereiam"," "+httpPost);
            httpPost.setEntity(new UrlEncodedFormEntity(params));
            HttpResponse httpResponse = httpClient.execute(httpPost);//<-----Error is here
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();
            Log.e("here"," "+is);
        }
        else if(method.equals("GET"))
        {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            String paramString = URLEncodedUtils.format(params, "utf-8");
            url += "?" + paramString;
            HttpGet httpGet = new HttpGet(url);
            HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();
            Log.e("here1"," "+is);
        }

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine())!=null)
        {
            sb.append(line + "'n");
        }
        is.close();
        json = sb.toString();
        Log.e("errors",json);
    }
    catch (Exception e)  {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }
    //return json string
    return jObj;
}

有人可以告诉我为什么会抛出空指针异常吗?

试试这个

<?php
$con=mysqli_connect("localhost","root","") or  die(mysql_error());
mysqli_select_db($con,"something")or die("Unable to connect 1");
$response = array();
$response["success"] = 0;
$email = $_POST['email']; 
$passwd = $_POST['pass']; 
$query1 = mysqli_query($con,"SELECT pass FROM userinfo where email='$email'");
   $res= mysqli_fetch_assoc($query1);
        if($res)
        {
             if($passwd!=$res['pass'])
            {                    
                $response["success"]=1;
                print(json_encode($response));
            }
            else 
            {                    
                $response["success"]=0;
                print(json_encode($response));          
            }
        }
        else
        {
            $response["success"]=0;
            print(json_encode($res));   
        }
?>