2013-04-16 87 views
0

我有一個應用程序從我的web服務(其餘)獲取數據(json)。我可以成功地 讓我的JSON。我所做的是這樣的:刪除我的json字符串中添加的轉義字符

  try{ 
      DefaultHttpClient httpClient = new DefaultHttpClient(); 
      httpClient.setCredentialsProvider(credProvider); 
      HttpGet httpGet = new HttpGet(url); 

      HttpResponse httpResponse = httpClient.execute(httpGet); 
      HttpEntity httpEntity = httpResponse.getEntity(); 
      inStream = httpEntity.getContent(); 
     } catch (UnsupportedEncodingException e) { 
      e.printStackTrace(); 
     } catch (ClientProtocolException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

     try{ 
      BufferedReader reader = new BufferedReader(new InputStreamReader(inStream)); 

      StringBuilder sb = new StringBuilder(); 
      String line = null; 

      while((line = reader.readLine()) != null){ 
       sb.append(line); 
      } 

      inStream.close(); 
      json = sb.toString(); 
     }catch(Exception e){ 
      logs... 
     } 

     // and so on... 

但是,當我嘗試打印我的json (String),因爲我有一個url從JSON了...... 我的URL看起來像這樣something\/image\/myimage.png insted的的something/image/myimage.png 我的問題在哪裏以及如何我可以刪除額外的「\」在我的網址。這是逃避角色嗎? 任何想法?如果你分享一些會很棒。雖然我目前也在尋找修補程序。但截至目前,我幾乎找不到它。

+0

檢查http://stackoverflow.com/questions/3537706/howto-unescape-a-java-string-literal-in-java – Naveen

回答

1

使用str.replaceALL(「\\\\」,「」)刪除轉義字符。

+0

謝謝,但沒有運氣...仍然我有那些字符 – elL

+0

,現在我想知道爲什麼沒有改變..這是因爲這是logcat顯示跟蹤的方式... – elL