简体   繁体   English

Python-如何将特殊字符转换为unicode表示形式?

[英]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.

相关问题 如何在python中将unicode字符表示形式从字符串转换为unicode? - How to convert a unicode character representation from string to unicode in python? 如何将unicode字符串的str表示形式转换为unicode? - How can I convert a str representation of a unicode string to unicode? Python 3:如何在变量中取值并将其转换为 unicode 字符? - Python 3: How can I take a value in a variable and convert that to a unicode character? 有没有一种简单的方法可以将Unicode字符表示形式转换为python中的实际字符。 - Is there an easy way to convert unicode character representation to actual characters in python. Python特殊字符Unicode - Python special character unicode 如何在python中将Shift_JIS字符代码转换为unicode字符? - How can I convert Shift_JIS character codes to unicode characters in python? 如何将特殊字符的字符串类型转换为原始字符? - how can I convert string type of special character into original? Python:用其Unicode表示形式替换字符 - Python: Replace character by its Unicode-representation 如何将字节对象转换为 python 中的十进制或二进制表示形式? - How can I convert bytes object to decimal or binary representation in python? Python-如何将Unicode代码点转换为字符 - Python - How to convert Unicode code point to the character
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM