Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android java replaceALL不工作(url空白到%20)_Android_Json_Replaceall - Fatal编程技术网

Android java replaceALL不工作(url空白到%20)

Android java replaceALL不工作(url空白到%20),android,json,replaceall,Android,Json,Replaceall,我的json文件包含空格,如1522663136车辆和自行车采购通知1.PDF。在browswer中,默认情况下添加了%20。但在android项目中使用此文件时,我无法逃避空白。我的json输出如下 "heading": "Notice", "content": "Tender Notice", "img": "1522663136Vehicle and Bike Procurement Notice 1.PDF" 我正在尝试使用replaceALL替换空白 但是它在Java中不起作用,字符

我的json文件包含空格,如1522663136车辆和自行车采购通知1.PDF。在browswer中,默认情况下添加了%20。但在android项目中使用此文件时,我无法逃避空白。我的json输出如下

"heading": "Notice",
"content": "Tender Notice",
"img": "1522663136Vehicle and Bike Procurement Notice 1.PDF"
我正在尝试使用replaceALL替换空白


但是它在Java中不起作用,字符串是不可变的,因此replaceAll返回一个新字符串,而不是更改现有字符串。试试这个:

pdf = pdf.replaceAll(" ","%20");

@jdigital的答案在技术上是正确的,但是您可以使用URLENCoderCode对整个URL进行编码。谢谢,我已经忘记了
pdf = pdf.replaceAll(" ","%20");