我正在尝试开发一个在PHP和我的移动应用程序之间使用JSON解析器的应用程序,我发现大多数时候应用程序正常运行,但很少次,少于10%会抛出结束时的错误以字符0
输入。任何人都可以简要解释一下我遇到了什么吗?
以下是我从PHP获取数据的代码:
public class getDataClass {
public void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy); }
public static String executeQuery() {
String result = "";
try {
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 6000);
HttpConnectionParams.setSoTimeout(httpParameters, 6000);
//check IF IP timeout
HttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpPost httpPost = new HttpPost("somephp.php");
//ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
// params.add(new BasicNameValuePair("query_string", query_string));
// httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
HttpResponse httpResponse = httpClient.execute(httpPost);
//view_account.setText(httpResponse.getStatusLine().toString());
HttpEntity httpEntity = httpResponse.getEntity();
InputStream inputStream = httpEntity.getContent();
BufferedReader bufReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"), 8);
StringBuilder builder = new StringBuilder();
String line = null;
while((line = bufReader.readLine()) != null) {
builder.append(line + "\n");
}
inputStream.close();
result = builder.toString();
} catch(Exception e) {
// Log.e("log_tag", e.toString());
}
return result;
}
}
以下是我在主要活动中使用的方法:
private String DLdata(){
String result = getDataClass.executeQuery();
if(result.startsWith("[")){
}else{
result = result.substring(1);
}
return result;
}