My code to get image Urls

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();

where server code is in php

But problem is there is extra \ before every / e.g. in database image Url is, http://www.dvimaytech.com/markphoto/upload/herwadeshirish123@Gmail.com/Pic.jpg but I get every time http:\/\/www.dvimaytech.com\/markphoto\/upload\/herwadeshirish123@Gmail.com\/Pic.jpg

Is this problem isn't solvable, then another solution(its last option for me) is to remove every .

But when I try that using url = url.replace("\",""); it gives syntax error String literal is not properly closed by a double-quote

有帮助吗?

解决方案

Just use a JSON parser library like gson to decode your JSON packets for you. http://code.google.com/p/google-gson/

It will make your life much easier and avoid having to string.replace() specific characters.

其他提示

You can use the following method to handle that

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;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top