JSON响应字符串中的转义字符 [英] Unescaping Characters in a JSON response string
本文介绍了JSON响应字符串中的转义字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发出了一个JSON请求,该请求给了我一个使用 Unicode字符代码的字符串像:
I made a JSON request that gives me a string that uses Unicode character codes that looks like:
s = "\u003Cp\u003E"
我想将其转换为:
s = "<p>"
在Python中执行此操作的最佳方法是什么?
What's the best way to do this in Python?
请注意,这与这一个是相同的问题,仅适用于Python(Ruby除外).我也在使用 Posterous API .
Note, this is the same question as this one, only in Python except Ruby. I am also using the Posterous API.
推荐答案
如果数据来自JSON,则json
模块应该已经为您解码了这些转义符:
If the data came from JSON, the json
module should already have decoded these escapes for you:
>>> import json
>>> json.loads('"\u003Cp\u003E"')
u'<p>'
这篇关于JSON响应字符串中的转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文