2016-05-29 81 views
-1

我有Android的JSON从MySQL解析一个问题,当我尝试执行我的项目,它告诉我“输入的字符0 org.json.jsonexception结束” 这是我的解析代码:如何解析json?

protected String doInBackground(String... arg0) { 
     for(String url: arg0){ 
      try{ 
      HttpClient httpclient = new DefaultHttpClient(); 
      HttpPost httppost = new HttpPost(url); 

      HttpResponse response = httpclient.execute(httppost); 
      inp = response.getEntity().getContent(); 
     } 
     catch (ClientProtocolException e){ 
      error = "ClientProtocolException: " + e.getMessage(); 
     }catch (IOException e){ 
      error = "ClientProtocolException: " + e.getMessage(); 
     } 

     } 
     BufferedReader reader; 

     try{ 
      reader = new BufferedReader(new InputStreamReader(inp, "iso-8859-1"),8); 
      String line=null; 
      while ((line = reader.readLine()) != null){ 
       txt += line+"\n"; 
      } 
      inp.close(); 

     }catch (UnsupportedEncodingException e){ 
      error = "Unsupport Encoding: "+e.getMessage(); 
     }catch (IOException e){ 
      error = "Error IO: "+e.getMessage(); 
     } 
     list1 = new ArrayList<Pharm>(); 

     try{ 

      JSONArray jArray = new JSONArray(txt); 

      for(int i=0;i<jArray.length();i++){ 
       JSONObject jsonData = jArray.getJSONObject(i); 


       Pharm pharm = new Pharm(); 
       pharm.setNomPharm(jsonData.getString("nomPharm")); 
       pharm.setAdressePharm(jsonData.getString("adressePharm")); 

       list1.add(pharm); 

      } 
     }catch (JSONException e){ 
      error = "Error convert to JSON or Error JSON format: "+ e.getMessage(); 
     } 
     return error; 
    } 

我需要你的帮助。

+1

你能告诉我们'JSON'回来了? –

+0

这将是一个** **必须为我们解决这个问题... – Vucko

+0

{ 药店:[{ idPharm: “1”, nomPharm: “pharm1”, adressePharm: “干草萨达”, lat:“ssssssss”, lon:“ddddddddd” } ] } –

回答