我正在使用Python 2.7并使用google plus public API来获取文件中的活动数据。我遇到了在我的文件中维护json编码的问题。双引号将在我的文件中出现。以下是我的代码:
from apiclient import discovery
API_KEY = 'MY API KEY'
service = discovery.build("plus", "v1", developerKey=API_KEY)
activities_resource = service.activities()
request = activities_resource.search(query='India versus South Africa', maxResults=1, orderBy='best',)
while request!= None:
activities_document = request.execute()
if 'items' in activities_document:
with open("output.json", mode='a') as file:
data = str(activities_document['items'])
file.write(data +"\n\n")
request = service.activities().list_next(request, activities_document)
输出: [{u'kind':u'plus#activity',u'provider':{u'title':u'Google +'},u'titl .......
我期待[{“kind”:“加#活动”,.....
我在Windows上运行我的代码,我在DOS和pycharm IDE上都试过了。我也在ubuntu机器上运行代码,但输出相同。请让我知道我做错了什么。