我在使用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活动传递。感谢