我有一个Android应用程序发送一个JSON字符串到我的服务器,它的格式如下:遇到问题解析JSON与PHP
{"drink_name":"testing","phone_number":"5555555555"}
当我使用命令:SELECT * FROM订单,这表明,空白条目被插入到表中。
我认为我的问题是由我的PHP脚本引起的(主要是因为我是PHP新手)。 我正确解析json吗? 下面是我写的脚本。编辑: 这是我的Android代码,如果它有任何帮助。
protected void sendJson(final String phnNmbr, final String drink) {
Thread t = new Thread(){
public void run() {
Looper.prepare(); //For Preparing Message Pool for the child Thread
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
HttpResponse response;
JSONObject json = new JSONObject();
try{
HttpPost post = new HttpPost("http://kubie.dyndns-home.com/R2Bar2/sendOrder.php");
json.put("phone_number", phnNmbr);
json.put("drink_name", drink);
StringEntity se = new StringEntity("orders: " + json.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
post.setEntity(se);
response = client.execute(post);
/*Checking response */
Toast.makeText(getApplicationContext(), json.toString(), Toast.LENGTH_LONG).show();
if(response!=null){
InputStream in = response.getEntity().getContent(); //Get the data in the entity
}
}
catch(Exception e){
e.printStackTrace();
//createDialog("Error", "Cannot Estabilish Connection");
}
Looper.loop(); //Loop in the message queue
}
};
t.start();
}
那么,'var_dump($ obj)'给你什么? – deceze 2012-04-02 06:45:27
另外,Android应用程序如何发送数据?请求是POST还是GET? – 2012-04-02 06:48:01
尝试开启错误报告/错误记录并再次检查输出。 – 2012-04-02 06:53:22