如何自动取消字符串中的转义字符

Pra*_*ani 2 java escaping

我正在从服务中接收带有转义序列字符的数据......我已设法通过此代码对其进行操作

results=results.replace("\\\"", "\"");
if(results.startsWith("\"")) {
    results=results.substring(1,results.length());
}
if(results.endsWith("\"")) {
    results=results.substring(0,results.length()-1); 
}
Run Code Online (Sandbox Code Playgroud)

它工作正常,但对于某些字符串,它会在创建json对象时抛出异常...如何自动取消结果中的转义字符,我已经搜索了答案,但其中许多人说要使用第三方库...什么是我能做到最好.

Evo*_*vos 5

我认为Apache Commons非常好用.它有StringEscapeUtils一堆类不同的静态方法用于转义和取消字符串,所以我认为你应该检查它.

祝好运!