0

我正在使用 URI Builder 类来构建这个 url http://image.tmdb.org/t/p/w185//qjn3fzCAHGfl0CzeUlFbjrsmu4c.jpg

这是我的代码:

       `final String TMDB_results = "results";
        final String TMDB_title = "original_title";
        final String TMDB_poster = "backdrop_path";

        JSONObject moviesJson = new JSONObject(moviesJsonStr);
        JSONArray resultArray = moviesJson.getJSONArray(TMDB_results);

        String[] resultnameStrs = new String[resultArray.length()];
        String[] resultposterStrs = new String[resultArray.length()];
        for (int i = 0; i < resultArray.length(); i++) {

            String moviename;
            String movieposter;

            // Get the JSON object in which movie title is there
            JSONObject movietitle = resultArray.getJSONObject(i);
            moviename = movietitle.get(TMDB_title).toString();
            movieposter = movietitle.get(TMDB_poster).toString();

            //Poster URL Builder
            Uri posterbuiltUri = Uri.parse("http://image.tmdb.org/t/p/w185/").buildUpon()
                    .appendPath(movieposter).build();
            String PosterUrl = posterbuiltUri.toString();

            resultposterStrs[i] = PosterUrl;
            resultnameStrs[i] = moviename;
        }

但是正在构建的 URL 是 http://image.tmdb.org/t/p/w185/%2Fqjn3fzCAHGfl0CzeUlFbjrsmu4c.jpg

这是我从中检索数据的 JSON 字符串的一部分:

{"page":1,"results":[{"adult":false,"backdrop_path":"/kvXLZqY0Ngl1XSw7EaMQO0C1CCj.jpg","genre_ids":[28,12,878],"id":102899,"original_language":"en","original_title":"Ant-Man","overview":"Armed with the astonishing ability to shrink in scale but increase in strength, con-man Scott Lang must embrace his inner-hero and help his mentor, Dr. Hank Pym, protect the secret behind his spectacular Ant-Man suit from a new generation of towering threats. Against seemingly insurmountable obstacles, Pym and Lang must plan and pull off a heist that will save the world.","release_date":"2015-07-17","poster_path":"/D6e8RJf2qUstnfkTslTXNTUAlT.jpg","popularity":54.222073,"title":"Ant-Man","video":false,"vote_average":6.9,"vote_count":1859},.......

我认为“/”被编码为“%2F”。有没有办法阻止它?

对此进行重新评分的任何帮助表示赞赏。

4

2 回答 2

1

appendPath正在对/图像路径中的字符进行编码——您可能会将%2F其视为已编码(又名 URL 安全)的替代方案。您在这里最快的选择是快速删除第一个斜杠(这也将防止来自基本 URL 和图像 URL 路径的双斜杠)。

Uri posterbuiltUri = Uri.parse("http://image.tmdb.org/t/p/w185/").buildUpon() .appendPath(movieposter.replace("/","").build();

于 2015-12-08T22:31:24.027 回答
0

你有一个额外的 '/' ,而不是编码:

http://image.tmdb.org/t/p/w185/qjn3fzCAHGfl0CzeUlFbjrsmu4c.jpg

于 2015-12-08T22:29:24.590 回答