我正在尝试从 php 脚本中查询如下:
http://xxxx.com/ccvo/mel-asset-data/query.php?lon=144.963620993985&lat=-37.8140023779914&within=20&category=Litter Bin
网页查询的结果将以纯文本形式显示,如下所示:
4|Litter Bin,-37.8141472000103,144.963691391683,17.2492037024|Litter Bin,
37.8141472763581,144.963685395193,17.0753971521|Litter Bin,
37.8139653160326,144.963765797949,13.3704129156|Litter Bin,
37.8139469233985,144.963755935562,13.3613106302
我需要将值传递给四个参数。到目前为止,我的代码出现错误 200,这意味着它可以访问网络。此外,查询的格式很好,什么时候做 Log.d 我得到以下信息:
query[lon=144.963620993985, lat=-37.8140023779914, within=4, keyword=Litter Bin]
然后我需要将结果解析如下:结果数,(经度和纬度),范围内,关键字
我的可能是:
public class myMapService extends AsyncTask<String, Void, Integer> {
private ProgressDialog progressDialog;
private keyword activity;
private int id = -1;
private String rst = " " ;
public myMapService(keyword activity, ProgressDialog progressDialog)
{
this.activity = activity;
this.progressDialog = progressDialog;
}
@Override
protected void onPreExecute()
{
progressDialog.show();
}
@Override
protected Integer doInBackground(String... arg0) {
String result = "";
int responseCode = 0;
try
{
HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://xxxx.com/ccvo/mel-asset-data/query.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("lon", "144.963620993985"));
nameValuePairs.add(new BasicNameValuePair("lat", "-37.8140023779914"));
nameValuePairs.add(new BasicNameValuePair("within", "20"));
nameValuePairs.add(new BasicNameValuePair("keyword", "Litter Bin"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8));
Log.v("URL", " with query" + nameValuePairs);
int executeCount = 0;
HttpResponse response;
do
{
progressDialog.setMessage("Passing paratmeters.. ("+(executeCount+1)+"/5)");
// Execute HTTP Post Request
executeCount++;
response = client.execute(httppost);
responseCode = response.getStatusLine().getStatusCode();
// If you want to see the response code, you can Log it
// out here by calling:
// Log.d("256 Design", "statusCode: " + responseCode)
//InputStream content = response.getEntity().getContent();
// Log.d("256 Design", " Response print" + response);
} while (executeCount < 5 && responseCode == 408);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuilder sb = new StringBuilder();
//Log.d("Results", " Inside whileloops " + rd);
String line;
while ((line = rd.readLine()) != null)
{
result = line.trim();
sb.append(line);
rst = result.toString();
}
Log.v("Results", "rst " + sb);
id = Integer.parseInt(result);
}
catch (Exception e) {
responseCode = 408;
e.printStackTrace();
}
Log.d("Results", "from web: " + rst);
return responseCode;
}
@Override
protected void onPostExecute(Integer headerCode)
{
progressDialog.dismiss();
}
}
当我对响应或 BufferedReader 执行 Log.d 时,我得到如下信息:
-java.io.BufferedReader@40fc93c8
-printorg.apache.http.message.BasicHttpResponse@40f746b8
我需要帮助以获取结果并解析它们。
谢谢你,A。