我正在尝试将一些数据解析为php中的表单。但是下面的内容正在发生 此代码中是否有任何错误,因为这会在log cat中打印webview的php echo,但这些值未在webview中显示。
x=getIntent().getStringExtra("name");
tot=getIntent().getStringExtra("total");
fuel=getIntent().getStringExtra("fuel");
phone=getIntent().getStringExtra("phone");
mail=getIntent().getStringExtra("driver_email");
Log.e("name", x);
try {
postData();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void postData() throws JSONException{
StrictMode.ThreadPolicy policy =
new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(payUrl);
JSONObject json = new JSONObject();
try {
// JSON data:
json.put("name", x);
json.put("total", tot);
json.put("fuel", fuel);
json.put("phone", phone);
json.put("mail", mail);
JSONArray postjson=new JSONArray();
postjson.put(json);
// Post the data:
httppost.setHeader("json",json.toString());
httppost.getParams().setParameter("jsonpost",postjson);
// Execute HTTP Post Request
System.out.print(json);
HttpResponse response = httpclient.execute(httppost);
// for JSON:
if(response != null)
{
InputStream is = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
y = sb.toString();
Log.e("y",y);
}
接收数据的php代码是
$data = json_decode($json);
echo "Array: \n";
echo "--------------\n";
var_dump($data,true);
echo "\n\n";
$name= $data->name;
$mail= $data->mail;
$phone= $data->phone;
$fuel= $data->fuel;
$total= $data->total;
$pos = $data->position;
echo $data->name;
echo "Result: \n";
echo "--------------\n";
echo "Name : ".$name."\n Position : ".$pos."\n mail: ".$mail."\n phone : ".$phone."\n fuel : ".$pos."\ total : ".$pos;
但是,当我试图回声值不弹出。任何帮助 我正在添加我的logcat和echo以获得更好的underxsxtanding
JSON: -------------- NULL Array: -------------- NULL Result: -------------- Name : Position : mail: phone : fuel : \ total :
Log Cat:
06-08 10:22:30.017: E/y(13205): JSON:
06-08 10:22:30.017: E/y(13205): --------------
06-08 10:22:30.017: E/y(13205): string(80) "{"name":"s","total":"82.73","fuel":"Petrol","phone":"22","mail":"abc@gmail.com"}"
06-08 10:22:30.017: E/y(13205): Array:
06-08 10:22:30.017: E/y(13205): --------------
06-08 10:22:30.017: E/y(13205): object(stdClass)#2 (5) {
06-08 10:22:30.017: E/y(13205): ["name"]=>
06-08 10:22:30.017: E/y(13205): string(1) "s"
06-08 10:22:30.017: E/y(13205): ["total"]=>
06-08 10:22:30.017: E/y(13205): string(5) "82.73"
06-08 10:22:30.017: E/y(13205): ["fuel"]=>
06-08 10:22:30.017: E/y(13205): string(6) "Petrol"
06-08 10:22:30.017: E/y(13205): ["phone"]=>
06-08 10:22:30.017: E/y(13205): string(2) "22"
06-08 10:22:30.017: E/y(13205): ["mail"]=>
06-08 10:22:30.017: E/y(13205): string(13) "abc@gmail.com"
06-08 10:22:30.017: E/y(13205): }
06-08 10:22:30.017: E/y(13205): sResult:
06-08 10:22:30.017: E/y(13205): --------------
06-08 10:22:30.017: E/y(13205): Name : s
06-08 10:22:30.017: E/y(13205): Position :
06-08 10:22:30.017: E/y(13205): mail: abc@gmail.com
06-08 10:22:30.017: E/y(13205): phone : 22
06-08 10:22:30.017: E/y(13205): fuel : \ total : fff