私のjsonファイルはきれいに印刷されています:
{u'count': 80,
u'data': [{u'comment': {u'activity_id': 41638,
u'date': u'4/2/2013 11:07:29 PM',
u'id': 3230,
u'message': u'I echo that. Thanks for jumping in at any moment without hesitation to take the lead on TMO deliverables; you have improved our relationship with an extremely valuable client.',
u'user': {u'first_name': u'Brent',
u'id': 4863,
u'last_name': u'Camalich',
u'picture': u'http://lunchbox.youearnedit.com/profile/4863/image/'}}},
{u'comment': {u'activity_id': 42577,
u'date': u'4/5/2013 12:29:16 AM',
u'id': 3384,
u'message': u'Thanks Greg! Go team Gamecenter!',
u'user': {u'first_name': u'Malik',
u'id': 7581,
u'last_name': u'Jones',
u'picture': u'http://lunchbox.youearnedit.com/profile/7581/image/'}}},
{u'comment': {u'activity_id': 42578,
u'date': u'4/5/2013 12:29:54 AM',
u'id': 3385,
u'message': u'Thanks Josh!! Appreciate the points! Let me know if you ever need anything.',
u'user': {u'first_name': u'Malik',
u'id': 7581,
u'last_name': u'Jones',
u'picture': u'http://lunchbox.youearnedit.com/profile/7581/image/'}}}],
u'page': 1,
u'page_count': 4,
u'page_size': 25}
、、、などのjsonファイルの最上位部分を返すことができますがcount
、 sのリストを取得するのに苦労しています。その後、リストからランダムに選んでコメントを見つけることを計画していました。どんな助けでも大歓迎ですpage
page_count
page_size
activity_id
#!/bin/python
import requests, json
from pprint import pprint
comments_url = "https://lunchbox:9e7cb94db13448209b1a66e71e145b7d@api.youearnedit.com/comments"
r = requests.get(comments_url)
json_data = r.json()
print "Comment Count"
print json_data["count"]
pprint(json_data)
activity_ids = [comment['activity_id'] for comment in json_data[1]['comments']]
for activity_id in activity_ids:
print activity_id