我正在尝试将 jsonarray 上传到服务器,然后获取响应文本以查看服务器对对象的作用。在android方面,我有这个代码:
HttpPost httppost = new HttpPost("http://10.0.0.2/namedate.php");I am
HttpClient httpclient = new DefaultHttpClient();
httppost.getParams().setParameter("jsonarray", json_a.toString());
HttpResponse response = httpclient.execute(httppost);
String responseText = EntityUtils.toString(response.getEntity());
Log.d("ProviderTester", "The response text is "+ responseText);
Log.i("JSONInfo","JSON object: " + json_a.toString());
jsonarray 从 logcat 看起来像这样:
04-10 21:29:53.293: I/JSONInfo(466): JSON object: ["[name=Mike, datetime=2012-04-10 21:29]","[name=Roger, datetime=2012-04-10 21:29]"]
目前我只是试图回显字符串,然后希望稍后将表格从字符串中取出:
<?php
echo $_POST['jsonarray'];
?>
以下是我从 logcat 得到的回复:
04-10 22:22:20.033: D/ProviderTester(499): The response text is
我该如何解决这个问题,以便我可以看到我发送到服务器的 jsonarray 字符串?
编辑:当我将我的 Android 代码更改为:
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("json_a", json_a.toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
String responseText = EntityUtils.toString(response.getEntity());
然后我使用接受的 php 脚本答案在 LogCat 中得到以下响应:
04-10 23:05:39.833: D/ProviderTester(601): The response text is POST = array (
04-10 23:05:39.833: D/ProviderTester(601): 'json_a' => '[name=Mike, datetime=2012-04-10 21:29]\\",\\"[name=Roger, datetime=2012-03-10 21:29]\\"]\\"]',
04-10 23:05:39.833: D/ProviderTester(601): )
04-10 23:05:39.833: D/ProviderTester(601): GET = array (
04-10 23:05:39.833: D/ProviderTester(601): )
04-10 23:05:39.833: D/ProviderTester(601): request = array (
04-10 23:05:39.833: D/ProviderTester(601): 'Content-Length' => '174',
04-10 23:05:39.833: D/ProviderTester(601): 'Content-Type' => 'application/x-www-form-urlencoded',
04-10 23:05:39.833: D/ProviderTester(601): 'Host' => 'graasdfon.hostei.com',
04-10 23:05:39.833: D/ProviderTester(601): 'Connection' => 'Keep-Alive',
04-10 23:05:39.833: D/ProviderTester(601): 'User-Agent' => 'Apache-HttpClient/UNAVAILABLE (java 1.4)',
04-10 23:05:39.833: D/ProviderTester(601): 'Expect' => '100-Continue',
04-10 23:05:39.833: D/ProviderTester(601): )
04-10 23:05:39.833: D/ProviderTester(601):
04-10 23:05:39.833: D/ProviderTester(601): <!-- www.000webhost.com Analytics Code -->
现在我只需要弄清楚如何处理 json_a 服务器端。谢谢您的帮助!