我想加載一個json文件,然後試圖稍後解析它。然而,在輸出中,我不停地收到'u'字符。 我試圖用encoding ='utf-8'打開這個文件,它能夠解決這個問題。 我正在使用python 2.7。有沒有一種簡單的方法或解決方法可以忽略並獲得輸出中的'u'字符。如何擺脫Python輸出的Unicode字符?
import json
import io
with io.open('/tmp/install-report.json', encoding='utf-8') as json_data:
d = json.load(json_data)
print d
O/P
{u'install': {u'Status': u'In Progress...', u'StartedAt': 1471772544,}}
PS:我去低谷這篇文章Suppress the u'prefix indicating unicode' in python strings 但沒有爲Python 2.7的解決方案
簡而言之:[** **無(http://stackoverflow.com/questions/761361 /抑制最uprefix-指示-Unicode的在-蟒-字符串)。 – Jan
爲什麼它是一個問題? –
Unicode與該問題無關。這是一個包含字符串的字典的Python('repr()')表示。如果您想以另一種格式(例如JSON)表示,則使用該格式的編碼器。 – bobince