0
我有選擇查詢mysql
它給我輸出像{"flag":"true"}
如何提取並比較HttpPost響應字符串?
在android代碼我怎麼能比較這個響應與任何字符串?
select.php代碼
<?php
$host='domain.com';
$uname='tempdata';
$pwd='tempdata';
$db="tempdata";
$con = mysql_connect($host,$uname,$pwd) or die("connection failed");
mysql_select_db($db,$con) or die("db selection failed");
$r=mysql_query("select * from test where message='hello'",$con);
while($row=mysql_fetch_array($r))
{
$flag[name]="true";
}
print(json_encode($flag));
mysql_close($con);
?>
在MainActivity.java
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.myweb.com/select.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Android的代碼,現在我要檢查響應與一些字符串,這樣我可以做進一步的操作。
for example
If response comes `true` then send email else not.
for that i need to check and compare for true value , how can I do so in android code?
這可能是有時間閱讀教程和/或應用一些代碼。無論如何,這個問題可能是「如何在Android中訪問/讀取JSON響應?」,這遠非罕見。 (但是請檢查*響應,當前發佈的PHP看起來無效,這完全是另一個問題。) – user2864740 2014-10-03 16:00:38