jsonpickle を使用するまで Twitter API の結果をシリアル化できませんでしたが (以下のコード A)、json ファイルをデコードできませんでした (以下のコード B)。コード A は、1 つの大きな json オブジェクトを作成しました。助けてください。
コード A
#!/usr/bin/env python
import tweepy
import simplejson as json
import jsonpickle
consumer_key = "consumer key here"
consumer_secret = "consumer secret here"
access_token = "access token here"
access_token_secret = "access token secret here"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, parser=tweepy.parsers.ModelParser())
jsonFile = open('/location_here/results.json', 'wb')
for status in tweepy.Cursor(api.search, q="keyword").items():
print status.created_at, status.text
frozen = jsonpickle.encode(status)
s = json.loads(frozen)
json.dump(s, jsonFile)
コード B
import jsonpickle
import simplejson as json
in_file = open("/location_here/results.json")
out_file = open("/location_here/data.json", 'wb')
jsonstr = in_file.read()
thawed = jsonpickle.decode(jsonstr)
data = json.loads(thawed)
これにより、エラー ValueError: Trailing data が発生します。
ありがとう。