[英]Simple way to remove escape characters from this JSON date
In my android application, my JSON date is returned as this: 在我的android应用程序中,我的JSON日期返回为:
\\/Date(1323752400000)\\/
Is there a simple way to remove the escape characters? 有一种简单的方法来删除转义符吗? (This is being sent from a WCF service to an Android application).
(这是从WCF服务发送到Android应用程序的)。 I am already using
StringEscapeUtils.unEscapeHtml4
to decode the entire serialized object. 我已经在使用
StringEscapeUtils.unEscapeHtml4
来解码整个序列化的对象。
actully this not works as it throws java.util.regex.PatternSyntaxException instead of using that use 实际上,这不起作用,因为它抛出java.util.regex.PatternSyntaxException而不是使用该用法
myJsonString=myJsonString.replaceAll("\\\\","");
it works fine 它工作正常
On the receiving end, if you really want to, you could just do myJsonString = myJsonString.replaceAll("\\\\","");
在接收端,如果您确实愿意,可以执行
myJsonString = myJsonString.replaceAll("\\\\","");
But do note that those escape characters in no way make the JSON invalid or otherwise semantically different -- the '/' character can be optionally escaped with '\\' in JSON. 但请注意,这些转义字符绝不会使JSON无效或在语义上有所不同-可以选择在JSON中使用'\\'来对'/'字符进行转义。
You can use Apache Commons lang : 您可以使用Apache Commons lang :
StringEscapeUtils.unescapeJava(stringToUnEscape);
Class Ref : https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscapeUtils.html 类别参考: https : //commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscapeUtils.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.