0

您好先生,我想将数据列表发送到 php 服务器我使用以下代码是否正确请告诉我

        i try this code
           ArrayList<String>list1=new ArrayList<String>();
    for(int i=0;i<json.length();i++)
    {
        JSONObject e = json.getJSONObject(i);
        list1.add(e.getString("menuname"));
    }

    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("menuname",list1.toString()));


        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://192.168.0.103/update.php");
        // "http://192.168.1.12/addnotes.php");
                //url+"Notes/addnotes.php");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
        Toast.makeText(getApplicationContext(),
                "Saved Sucessfully", Toast.LENGTH_SHORT).show()

请看上面的代码是否正确..请告诉我

4

1 回答 1

0

我认为您想正确获取 String 中的内容而不是使用它

String mResponseText = EntityUtils.toString(entity);  

插入

  is= entity.getContent();

可以帮助你吗

于 2012-04-06T10:31:02.993 回答