Java PHP服务器未使用JSON对象连接

Java PHP服务器未使用JSON对象连接,java,android,sql-server,json,Java,Android,Sql Server,Json,我无法从服务器检索数据。我不确定我在代码中哪里出错了..当我运行应用程序时,来自服务器的数据不会显示在模拟器上。。代码如下所示 private void postData1(){ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( "http://www.xxxxx.co.uk/NottTest/post.php"); JSONObject json = ne

我无法从服务器检索数据。我不确定我在代码中哪里出错了..当我运行应用程序时,来自服务器的数据不会显示在模拟器上。。代码如下所示

private void postData1(){


HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost(
        "http://www.xxxxx.co.uk/NottTest/post.php");

JSONObject json = new JSONObject();

try {

    // JSON data:

    try {
        json.put("name", "Fahmi Rahman");
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    json.put("position", "sysdev");

    JSONArray postjson = new JSONArray();

    postjson.put(json);

    // Post the data:

    httppost.setHeader("json", json.toString());

    httppost.getParams().setParameter("jsonpost", postjson);

    // Execute HTTP Post Request

    System.out.print(json);

    HttpResponse response = httpclient.execute(httppost);
    tv.setText("Hiii");

    // for JSON:

    if (response != null)

    {
        Log.i("Json","respose");
        System.out.print("loooooooooool");


        InputStream is = response.getEntity().getContent();

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(is));

        StringBuilder sb = new StringBuilder();

        String line = null;

        try {

            while ((line = reader.readLine()) != null) {

                sb.append(line + "\n");

            }

        } catch (IOException e) {

            e.printStackTrace();

        } finally {

            try {

                is.close();

            } catch (IOException e) {

                e.printStackTrace();

            }

        }

        text = sb.toString();

    }

    else{
        tv.setText("no respose");
        Log.i("Noting","happended");
    }

    //tv.setText(text);

} catch (ClientProtocolException e) {

    Log.i("Error","Prtocol");


} catch (IOException e) {

    Log.i("Error","IO");

} catch (JSONException e) {
    Log.i("Error","JOSON");
}

}我认为错误在

try {
        json.put("name", "Fahmi Rahman");
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    json.put("position", "sysdev");

    JSONArray postjson = new JSONArray();

我认为错误在于

try {
        json.put("name", "Fahmi Rahman");
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    json.put("position", "sysdev");

    JSONArray postjson = new JSONArray();

当您运行此代码时会发生什么情况?没有显示任何内容..因为它没有连接到服务器当您运行此代码时会发生什么情况?没有显示任何内容..因为它没有连接到服务器