bad encoding for xml
I have a string like this " <person name="peter" ><\person>"
URL encoding
URLEncoder.encode(person.toString(),"UTF-8");
but the encoding is bad because for spaces make +
insted of %20
and for 开发者_Python百科=
he gives other values can you guys help me?
This is exactly as specified in the URLEncoder
javaDoc. Space is converted to +
and =
is "unsafe" and thus encoded to %3D
.
If you need a %20
instead of the +
, just do some post processing:
URLEncoder.encode(person.toString(),"UTF-8").replace("+", "%20");
Considering your comment I assume you want to decode the webservice answer.
// the answer you receive from the webservice
string webserviceResponse = "%3Cperson+name%3D%22peter%22%3E%3C%2Fperson%3E";
// turn into a "good" Xml string
string person = URLDecoder.decode(webserviceResponse, "UTF-8");
will give you
<person name="peter"></person>
as the value of person
.
精彩评论