使用python在json文件中查找随机注释

时间:2013-05-09 08:17:40

标签: python json

我的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文件的顶级部分,例如countpagepage_countpage_size,但我很难获得{的列表{1}}秒。之后我计划从列表中随机挑选以找到评论。任何帮助表示赞赏

activity_id

1 个答案:

答案 0 :(得分:0)

知道了。

for item in json_data['data']:
    comment = item['comment']
    print comment['activity_id']