嗨,我想将 JSON 发布到 PHP 脚本。 这是代码:
JSONObject obj = new JSONObject();
for(int k = 0; k<len;k++){
obj.put("nachrichten_ids", params[k]);
}
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("xxxxxx");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("nachrichten_ids",obj.toString()));
httpPost.setHeader("Content-type", "application/json");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
PHP 脚本实际上只包含 print_r($_POST),并且每次都是空的。
问题出在哪里 ?
Log.i("TEST",obj.toString()) 输出: {"nachrichten_ids":"[2144,2138]"}
其中每个数字都是应删除的消息的 IDS。