我正在使用URI生成器类来构建此urlhttp://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;
}
但是正在构建的URLhttp://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"。有什么办法阻止这种情况吗?
如有任何帮助,我们将不胜感激。
appendPath
正在对图像路径中的/
字符进行编码——您可能会将%2F
视为已编码(又称URL安全)的替代方案。在这里,你最快的选择是快速删除第一个斜杠(这也将防止基URL和图像URL路径出现双斜杠)。
Uri posterbuiltUri = Uri.parse("http://image.tmdb.org/t/p/w185/").buildUpon()
.appendPath(movieposter.replace("/","").build();
您有一个额外的'/',请将其编码为:
http://image.tmdb.org/t/p/w185/qjn3fzCAHGfl0CzeUlFbjrsmu4c.jpg