[英]Python - How can I convert a special character to the unicode representation?
In a dictionary, I have the following value with equals signal: 在字典中,我具有以下等于信号的值:
{"appVersion":"o0u5jeWA6TwlJacNFnjiTA=="}
To be explicit, I need to replace the =
for the unicode representation '\='
(basically the reverse process of [json.loads()][1]
). 为了明确[json.loads()][1]
,我需要将Unicode表示形式'\='
替换为=
(基本上是[json.loads()][1]
的反向过程)。 How can I set the unicode value to a variable without store the value with two scapes ( \\\=
)?. 如何将unicode值设置为变量,而又不使用两个换码符( \\\=
)存储该值?
I've tryed of different ways, including the enconde/decode, repr(), unichr(61), etc, and even searching a lot, cound't find anything that does this, all the ways give me the following final result (or the original result): 我尝试了不同的方法,包括enconde / decode,repr(),unichr(61)等,甚至进行了很多搜索,都找不到能做到这一点的方法,所有方法都给我以下最终结果(或原始结果):
'o0u5jeWA6TwlJacNFnjiTA\\u003d\\u003d'
Since now, thanks for your attention. 从现在开始,感谢您的关注。
EDIT 编辑
When I debug the code, it gives me the value of the variable with 2 escapes. 当我调试代码时,它为我提供了2个转义符的变量值。 The program will get this value and use it to do the following actions, including the extra escape. 程序将获取此值并将其用于执行以下操作,包括额外的转义。 I'm using this code to construct a json by the json.dumps()
and the result returned is a unicode with 2 escapes. 我正在使用此代码通过json.dumps()
构造一个json,返回的结果是带有2个转义json.dumps()
的unicode。
Follow a print of the final result after the JSON construction. 遵循JSON构建后的最终结果打印。 I need to find a way to store the value in the var with just one escape. 我需要找到一种方法,只需一个转义即可将值存储在var中。
I don't know if make difference, but I'm doing this to a custom BURP Plugin, manipulating some selected requests. 我不知道是否有所作为,但是我正在对一个自定义的BURP插件执行此操作,以处理一些选定的请求。
Here is an image of my POC, getting the value of the var. 这是我的POC的图像,获取var的值。
The extra backslash is not actually added, The Python interpreter uses the repr() to indicate that it's a backslash not something like \\t or \\n when the string containing \\ gets printed: I hope this helps: 实际上并没有添加额外的反斜杠,当包含\\的字符串被打印时,Python解释器使用repr()表示它是反斜杠,而不是\\ t或\\ n:我希望这会有所帮助:
>>> t['appVersion'] = t["appVersion"].replace('=', '\u003d')
>>> t['appVersion']
'o0u5jeWA6TwlJacNFnjiTA\\u003d\\u003d'
>>> print(t['appVersion'])
o0u5jeWA6TwlJacNFnjiTA\u003d\u003d
>>> t['appVersion'] == 'o0u5jeWA6TwlJacNFnjiTA\u003d\u003d'
True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.