Java 如何编写php代码来显示I';我正在发送到服务器?

Java 如何编写php代码来显示I';我正在发送到服务器?,java,php,android,Java,Php,Android,我试图将jsonarray上载到服务器,然后获取响应文本,以查看服务器对对象做了什么。在android方面,我有以下代码: HttpPost httppost = new HttpPost("http://10.0.0.2/namedate.php");I am HttpClient httpclient = new DefaultHttpClient(); httppost.getParams().setParamete

我试图将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]"]
04-10 22:22:20.033: D/ProviderTester(499): The response text is 
目前,我只是想回显字符串,希望以后能从字符串中取出表格:

   <?php

    echo $_POST['jsonarray'];

   ?>
如何修复此问题,以便查看发送到服务器的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());
ArrayList nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“json_a”,json_a.toString());
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
HttpResponse response=httpclient.execute(httppost);
字符串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 -->
04-10 23:05:39.833:D/ProviderTester(601):响应文本为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/供应商测试仪(601):)
04-10 23:05:39.833:D/ProviderTester(601):获取=阵列(
04-10 23:05:39.833:D/供应商测试仪(601):)
04-10 23:05:39.833:D/ProviderTester(601):请求=阵列(
04-10 23:05:39.833:D/ProviderTester(601):“内容长度”=>“174”,
04-10 23:05:39.833:D/ProviderTester(601):“内容类型”=>“应用程序/x-www-form-urlencoded”,
04-10 23:05:39.833:D/ProviderTester(601):“主机”=>“graasdfon.hostei.com”,
04-10 23:05:39.833:D/ProviderTester(601):“连接”=>“保持活动”,
04-10 23:05:39.833:D/ProviderTester(601):“用户代理”=>“Apache HttpClient/UNAVAILABLE(java 1.4)”,
04-10 23:05:39.833:D/ProviderTester(601):“预期”=>“100继续”,
04-10 23:05:39.833:D/供应商测试仪(601):)
04-10 23:05:39.833:D/供应商检测仪(601):
04-10 23:05:39.833:D/供应商检测仪(601):

现在我只需要弄清楚如何在服务器端处理json。谢谢你的帮助

我不知道是什么原因导致了您的问题(我不知道Android/Java),但最好的调试方法是在PHP中对此进行简单的调试:

<?php
    var_dump($_POST);
?>


这将导致PHP输出它通过POST接收到的所有内容。

我不知道是什么导致了您的问题(我不知道Android/Java),但调试它的最佳方法是在PHP中简单地执行以下操作:

<?php
    var_dump($_POST);
?>


这将导致PHP输出通过POST接收到的所有内容。

您需要在POST的实体中传递json值。试试这个:

StringEntity params =new StringEntity(json_a.toString());
httppost.addHeader("content-type", "application/x-www-form-urlencoded");
httppost.setEntity(params);
而不是:

httppost.getParams().setParameter("jsonarray", json_a.toString());

您需要在post的实体中传递json值。试试这个:

StringEntity params =new StringEntity(json_a.toString());
httppost.addHeader("content-type", "application/x-www-form-urlencoded");
httppost.setEntity(params);
而不是:

httppost.getParams().setParameter("jsonarray", json_a.toString());
echo$_POST['jsonarray']

PHP无法对非标量数据类型进行隐式toString()表示。您需要进行显式转换

e、 g.如果要查看所有HTTP变量和请求头,请尝试以下操作:

<?php

$out="POST = " . var_export($_POST, true) . "\n";
$out.="GET = " . var_export($_GET, true) . "\n";
$out.="request = " . var_export(getallheaders(), true) . "\n";
print $out;

?>

(这不会拾取写入STDIN但未作为帖子正确嵌入的内容)

echo$_POST['jsonarray']

PHP无法对非标量数据类型进行隐式toString()表示。您需要进行显式转换

e、 g.如果要查看所有HTTP变量和请求头,请尝试以下操作:

<?php

$out="POST = " . var_export($_POST, true) . "\n";
$out.="GET = " . var_export($_GET, true) . "\n";
$out.="request = " . var_export(getallheaders(), true) . "\n";
print $out;

?>


(这不会拾取写入STDIN但未作为帖子正确嵌入的内容)

hmm,我在所有不同的php配置中尝试了此方法,响应文本为:array(0){}hmm,我在所有不同的php配置中尝试了此方法,响应文本为:array(0){}谢谢您的帮助!你知道现在如何从服务器端获取信息吗?谢谢你的帮助!你知道现在如何从服务器端获取信息吗?