在java中将编码字符串转换为可读字符串

在java中将编码字符串转换为可读字符串,java,c#,string,unicode,encoding,Java,C#,String,Unicode,Encoding,我正试图从一个C#程序向我的java服务器发送一个POST请求。 我将请求与一个json对象一起发送。 我在服务器上接收请求,可以使用以下java代码读取发送的内容: BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); OutputStream out = conn.getOutputStream(); String line = reader.readLine();

我正试图从一个C#程序向我的java服务器发送一个POST请求。 我将请求与一个json对象一起发送。 我在服务器上接收请求,可以使用以下java代码读取发送的内容:

BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
OutputStream out = conn.getOutputStream();
String line = reader.readLine();
String contentLengthString = "Content-Length: ";
int contentLength = 0;
while(line.length() > 0){   
    if(line.startsWith(contentLengthString))
        contentLength = Integer.parseInt(line.substring(contentLengthString.length()));             
    line = reader.readLine();
}       
char[] temp = new char[contentLength];
reader.read(temp);  
String s = new String(temp);
字符串s现在是我从C#client发送的json对象的表示形式。然而,有些角色现在被搞乱了。 原始json对象:

{"key1":"value1","key2":"value2","key3":"value3"}
收到的字符串:

%7b%22key1%22%3a%22value1%22%2c%22key2%22%3a%22value2%22%2c%22key3%22%3a%22value3%22%%7d

所以我的问题是:如何转换接收到的字符串,使其看起来像原始字符串?

看起来像是URL编码的,那么为什么不使用
java.net.urldecker

String s = java.net.URLDecoder.decode(new String(temp), StandardCharsets.UTF_8);

这是假设字符集实际上是UTF-8,这些字符看起来是URL编码的,所以我会像这样使用

注意,您的示例中似乎有一个额外的百分比,因为上面的打印

{"key1":"value1","key2":"value2","key3":"value3"}

那个复制品的可能复制品是坏的。接受答案的作者从未费心更新他们的答案(使用不推荐的方法调用)。下面的答案更好。
{"key1":"value1","key2":"value2","key3":"value3"}