\\\ u00c3 \\\ u00a9在哪个世界变成é?
我有一个来自我无法控制的来源的json文件,可能编码不正确,其中包含以下字符串:
d\u00c3\u00a9cor
business\u00e2\u20ac\u2122 active accounts
the \u00e2\u20ac\u0153Made in the USA\u00e2\u20ac\u009d label
因此,我正在收集他们打算使用\u00c3\u00a9
befom的方法é
,该方法将是utf-8 hex C3
A9
。这很有道理。对于其他情况,我假设我们正在处理某些类型的定向引号。
我的理论是,这要么是使用以前从未遇到过的某种编码,要么是以某种方式对其进行了双重编码。我很好地编写了一些代码,将他们破碎的输入转换成我可以理解的东西,因为如果我提请他们注意,他们不太可能能够修复该系统。
有什么主意如何使他们的投入变为我能理解的东西吗?作为记录,我正在使用Python。
-
您应该尝试ftfy模块:
>>> print ftfy.ftfy(u"d\u00c3\u00a9cor") décor >>> print ftfy.ftfy(u"business\u00e2\u20ac\u2122 active accounts") business' active accounts >>> print ftfy.ftfy(u"the \u00e2\u20ac\u0153Made in the USA\u00e2\u20ac\u009d label") the "Made in the USA" label >>> print ftfy.ftfy(u"the \u00e2\u20ac\u0153Made in the USA\u00e2\u20ac\u009d label", uncurl_quotes=False) the “Made in the USA” label