我正在用请求库进行restapi调用。 response = requests.get("https://urltomaketheapicall", headers={'authorization': 'bearer {0}'.format("7777777777777777777777777777")}, timeout=5)
当我这么做的时候 response.json()
我得到一个有这些值的键 {'devices': '....iPhone\xa05S, iPhone\xa06, iPhone\xa06\xa0Plus, iPhone\xa06S'}
当我这么做的时候 print(response.encoding)
我明白了 None
当我这么做的时候 print(type(data[devices]))
我明白了 <class 'str'>
如果我这样做了 print(data[devices])
我明白了 '....iPhone 5S, iPhone 6, iPhone 6 Plus, iPhone 6S'
没有特殊字符。
现在如果你想
new_dict={}
new_val = data[devices]
new_dict["devices"] = new_val
print(new_dict["devices"])
我也会在新字典里找到特殊字符。
有什么想法吗?
我想去掉这些特殊字符,因为我需要读取这些json并将其放入pysparkDataframe中,然后用这些字符生成一个\u损坏的\u记录
rd= spark.sparkContext.parallelize([data])
df = spark.read.json(rd)
我想避免像这样的解决方案 .replace("\\xa0"," ")
1条答案
按热度按时间vsaztqbk1#
A0
是一个不间断的空间。它只是弦的一部分。它只是这样打印,因为您正在转储整个dict的repr。如果您打印单个字符串,它将只打印为正确的无中断空格: