2013-04-16 85 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