java - extra\in json 响应之前/在 java、android 中

标签 java android url escaping jsonresult

我的代码获取图像网址

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("\",""); 它给出语法错误字符串文字未正确用双引号关闭

最佳答案

只需使用像 gson 这样的 JSON 解析器库来为您解码 JSON 数据包。 http://code.google.com/p/google-gson/

这将使您的生活变得更加轻松,并避免使用 string.replace() 特定字符。

关于java - extra\in json 响应之前/在 java、android 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14066259/

相关文章:

java - JMeter JavaSamplerClient 当前线程&所有线程

Java 和 Tomcat org.json java.lang.ClassNotFoundException

java - 如何在 Apache Jena 模型中添加 NameSpace/PrefixMap?

android - 在Android上未调用html5音频对象ondurationchange

c# - 如何在桌面应用程序和网站之间访问图像

java - 如果下一个标记与任何指定的字符串都不匹配,如何抛出 InputMismatchException?

java - 如何在 Xtend 的 Active Annotations 中获得完整的返回类型转发?

java - 有人可以帮助我吗?我怎么了 Volley 获取请求

javascript - 使用 javascript 检查 URL 是否包含值

python - git 文件夹下载实用程序与 python?