我的代码获取图片网址
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream inputStream = httpEntity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"), 8);
StringBuilder stringBuilder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
stringBuilder.append(line + "\n");
}
inputStream.close();
return stringBuilder.toString();
服务器代码在php中
但问题是每个/之前有额外的\
例如在数据库图像中,网址为http://www.dvimaytech.com/markphoto/upload/herwadeshirish123@Gmail.com/Pic.jpg
但我每次都会得到http:\/\/www.dvimaytech.com\/markphoto\/upload\/herwadeshirish123@Gmail.com\/Pic.jpg
这个问题是不是可以解决的,那么另一个解决方案(对我来说是最后一个选项)就是删除所有问题。
但是当我尝试使用url = url.replace("\","");
时
它给出了语法错误String literal is not properly closed by a double-quote
答案 0 :(得分:2)
只需使用像gson这样的JSON解析器库来为您解码JSON数据包。 http://code.google.com/p/google-gson/
它将使您的生活更轻松,并避免使用string.replace()特定字符。
答案 1 :(得分:1)
您可以使用以下方法来处理
public static String extractFileName(String path) {
if (path == null) {
return null;
}
String newpath = path.replace('\\', '/');
int start = newpath.lastIndexOf("/");
if (start == -1) {
start = 0;
} else {
start = start + 1;
}
String pageName = newpath.substring(start, newpath.length());
return pageName;
}