我已經做原料得到休息和崗位,也可以做後在的NameValuePair但無論我遵循的教程中,我只是不能得到JSON後做...Android的JSON後到PHP
Android應用程序:
ArrayList<String> stringData = new ArrayList<String>();
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost postMethod = new HttpPost("http://192.168.1.10/people.php");
JSONObject holder = new JSONObject();
holder.put("name", "Foo");
holder.put("occupation", "Bar");
StringEntity se = new StringEntity(holder.toString());
postMethod.setEntity(se);
postMethod.setHeader("Accept", "application/json");
postMethod.setHeader("Content-type", "application/json");
ResponseHandler <String> resonseHandler = new BasicResponseHandler();
String response=httpClient.execute(postMethod,resonseHandler);
stringData.add(response);
return stringData;
PHP文件:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
var_dump($_POST);
}
後續代碼var_dump只是給出了一個空數組和$ _ POST [ 「名稱」]給出不確定的指數...任何幫助將是不錯的讀取POST數據
也許你需要在你的php代碼中解碼它。如果需要解碼,請使用'$ jsonstring = urldecode($ _ REQUEST ['myjson'];' –
這個答案對我有用:) – code4j