使用 Python 从转义的 Unicode 解码为阿拉伯语



我试图解码一个转义了 unicode 文本的 json 文件/uHHH..原始文本是阿拉伯语

我的研究使我使用Python编写了以下代码。

s = 'u00d8u00b5u00d9u0088u00d8u00b1 u00d8u00a7u00d9u0084u00d9u008au00d9u0088u00d9u0085u00d9u008au00d8u00a7u00d8u00aa'
ouy= s.encode('utf-8').decode('unicode-escape').encode('latin1').decode('utf-8')
print(ouy)

结果文本将为:صÙر اÙÙÙÙÙات仍然需要使用在线工具进行一些修复才能成为原始文本:صور اليوميات

有没有办法使用上面的代码执行该修复? 感谢您的帮助,提前感谢

您可以使用此脚本更新所有 JSON 文件

import json
filename = 'YourFile.json'  # file name we want to compress
newname = filename.replace('.json', '.min.json')  # Output file name
with open(filename, encoding="utf8") as fp:
print("Compressing file: " + filename)
print('Compressing...')
jload = json.load(fp)
newfile = json.dumps(jload, indent=None, separators=(',', ':'), ensure_ascii=False)
newfile = newfile.encode('latin1').decode('utf-8') # remove this
#print(newfile)
with open(newname, 'w', encoding="utf8") as f:  # add encoding="utf8"
f.write(newfile)
print('Compression complete!')

解码Json到起源

最新更新