JSON을 다음과 같이 인코딩하려고합니다. 하지만이 경우 실제로는 unicode character DEVANAGARI LETTER 인 message
입니다.JSON 인코딩 파이썬에서 백 슬래시를 이스케이프 처리합니다.
이렇게 dict
을 json 개체로 인코딩하는 동안 message
에 두 개의 백 슬래시 ("\")가있는 백 슬래시 ("\")를 이스케이프 처리하는 것으로 보입니다.
어떻게 JSON으로 encode
에 하나의 백 슬래시 "\"json.dumps()
그것을 인코딩 후 나는 다음 custom encoder
을 사용하고로 DICT을 변경할 않습니다. \u
이스케이프 시퀀스가 컴파일러를하는 대신 이해되도록
class MyCustomJsonEncoder(json.JSONEncoder):
def encode(self, obj):
# the json obj
count = 0
for ob in obj:
obj[count]['message'] = unicode(obj[count]['message']).replace("\\u","\u")
count += 1
return super(MyCustomJsonEncoder, self).encode(obj)
[{
'virality': '4.6%',
'post_engaged': 150,
'description': '',
'post_impressions': 1631,
'post_story': 75,
'name': '',
'source': '',
'comment_count': 16,
'link': '',
'text': '',
'created_time': '03:10 AM,<br>May 13, 2013',
'message': '\u092e\u0941\u0930\u0932\u0940 \u0938\u093e\u0930:- \u0939\u0947 \u092e\u0940\u0920\u0947',
'id': u'182929845081087_572281819479219',
'status_type': 'status',
'likes_count': 55
}]
'덤프 (dumps)'에 '보장 _ 옵션'을 전달하면 코드의 다른 부분이 중단되는지 여부는 확실치 않지만 원하는대로 작동합니다. 그러나 그것이 정말로 당신의 문제를 해결하는지 알아 보는 것이 가치가있을 수 있습니다. [docs here] (http://docs.python.org/2/library/json.html#basic-usage) – naiquevin
을 참조하십시오. Nope ensure_ascii는 아무 효과가 없습니다. –
'message' 값을 유니 코드 – naiquevin