2017-10-17 1 views
0
내가 매개 변수 ensure_ascii와 JSON 파일을 작성하려는

= 거짓 어떻게 든 항상 나에게= 거짓

인가 "는 JSON 직렬화하지 --is"일부 오류가 있습니다 secured_ascii = False로 JSON 파일을 작성하는 또 다른 방법은 없을까요?

** 파이썬 2.7

ret = twitter_stream.statuses.filter(track='สวัสดี') 
 

 
tweet_count = 3 for tweet in ret: 
 
    tweet_count -= 1 
 
    # We convert it back to the JSON format to print/score 
 
    print ('----',tweet_count,'----') 
 
    #print json.dumps(tweet,ensure_ascii=False,indent=4) 
 
    if tweet_count <= 0: 
 
     break 
 

 
with io.open('data1.json', 'w', encoding='utf-8') as outfile: 
 
    outfile.write(json.dumps(ret, ensure_ascii=False, indent=4)) 
 
print("Done")

+0

json.dumps 전에'type (tweet)'하고 출력은 무엇입니까? – MohitC

+0

출력은 patppd

답변

0

귀하의 ret이 반복자 클래스 개체입니다 사용하고, 클래스 객체는 따라서 캔트 당신이 필요로하는 json.dumps

와 함께 사용할 수 직렬화 JSON되지 않습니다 해야 할 일 :

for tweet in ret: 
    with io.open('data1.json', 'a', encoding='utf-8') as outfile: 
     outfile.write(json.dumps(tweet, ensure_ascii=False, indent=4)) 
+0

입니다. 정말 고마워요 !! – patppd