What is the difference between unescapeJava and unescapeJson from StringEscapeUtils

huangapple go评论55阅读模式
英文:

What is the difference between unescapeJava and unescapeJson from StringEscapeUtils

问题

根据StringEscapeUtils文档,似乎这两个方法unescapeJsonunescapeJava执行的是类似的操作。

我尝试使用这两种方法,它们都正常工作,如下所示:

示例:

String input = ""{"key":"ab\u2019cd"}"";
System.out.println(unescapeJava(input)); // 输出:{"key":"ab’cd"}
System.out.println(unescapeJson(input)); // 输出:{"key":"ab’cd"}

这两个语句打印的输出完全相同。那么,它们之间有什么区别,以及何时使用哪种方法?

英文:

As per the StringEscapeUtils documentation, looks like both these methods unescapeJson and unescapeJava does the similar thing.

I tried using both methods it works fine as below:

Example:

String input = "{\"key\":\"ab\u2019cd\"}"
System.out.println(unescapeJava(input)); // outputs: {"key":"ab’cd"}
System.out.println(unescapeJson(input)); // outputs: {"key":"ab’cd"}

Both of these statements print exactly same output. So, what is the difference and when to use which method?

答案1

得分: 3

They are the same, as you can see in the sources:

public static final CharSequenceTranslator UNESCAPE_JSON = UNESCAPE_JAVA;
英文:

They are the same, as you can see in the sources:

public static final CharSequenceTranslator UNESCAPE_JSON = UNESCAPE_JAVA;

huangapple
  • 本文由 发表于 2020年8月5日 22:06:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63266971.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定