2016-05-29 108 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」 } ] } –

回答