我在使用 JSONArray 解析时遇到问题 我的日志错误是
09-07 16:00:23.516:E/log_tag(216):解析 dataorg.json.JSONException 时出错:JSONArray 文本必须在字符 5 处以“[”开头
我的活动是
public class Httppostaux {
InputStream is =null;
String result ="";
public JSONArray getserverdata(ArrayList<NameValuePair>parameters,String urlwebserver){
//conexion mediante un http y envío mediante post
httppostconnect(parameters,urlwebserver);
if(is!=null){//si hay respuesta
getpostresponse();
return getjsonarray();
}else{
return null;
}
}
//peticion HTTP
private void httppostconnect(ArrayList<NameValuePair>parametros,String urlwebserver){
try{
HttpClient httpclient=new DefaultHttpClient();
HttpPost httppost=new HttpPost(urlwebserver);
httppost.setEntity(new UrlEncodedFormEntity(parametros));
//ejecuta peticion enviando datos por post
HttpResponse response=httpclient.execute(httppost);
HttpEntity entity=response.getEntity();
is=entity.getContent();
}catch(Exception e){
Log.e("Log_taf","Error in http connection"+e.toString());
}
}
public void getpostresponse(){
//convierte respuesta a string
try{
BufferedReader reader=new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb=new StringBuilder();
String line =null;
while ((line = reader.readLine())!=null){
sb.append(line + "\n");
}
is.close();
result=sb.toString();
Log.e("gestpostresponse","result= "+sb.toString());
}catch(Exception e){
Log.e("log_tag","Error converting result"+e.toString());
}
}
public JSONArray getjsonarray(){
//parse json data
try{
JSONArray jArray = new JSONArray(result);
return jArray;
}
catch(JSONException e){
Log.e("log_tag","Error parsing data"+ e.toString());
return null;
}
}
}
我正在验证用户并通过 Logi 活动。谢谢