json 파일을로드하고 나중에 구문 분석하려고합니다. 그러나 출력에서 'u'문자가 계속 표시됩니다. 문제를 해결하는 인코딩 = 'utf-8'로 파일을 열려고했습니다. 파이썬 2.7을 사용하고 있습니다. 출력에서 'u'문자를 무시하고 타는 직접적인 접근법이나 해결 방법이 있습니까?파이썬 출력에서 유니 코드 문자를 제거하는 방법은 무엇입니까?
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,}}
추신 :이 게시물 Suppress the u'prefix indicating unicode' in python strings 물마루 갔다하지만 사용 json.dumps 파이썬 2.7을위한 솔루션
: [** 없음 **] (http://stackoverflow.com/questions/761361/suppress-the-uprefix-indicating-unicode-in-python-strings). – Jan
왜 문제입니까? –
유니 코드는이 문제와 아무 관련이 없습니다. 이것은 문자열로 가득 찬 사전의 파이썬 ('repr()') 표현입니다. JSON과 같은 다른 형식의 표현을 원할 경우 해당 형식에 대한 인코더를 사용하십시오. – bobince