2015-02-17 77 views
1

我想在应用程序中编写一小段代码来检查用户是否关注您。我只想让代码返回一个True/False值,我可以把它放在一个if循环中。从JSON Twitter响应(Tweepy和Python)中提取单个True/False值

的代码是:

user_id = '1234567890' 
print api.show_friendship(target_id=user_id) 

,并返回这一切的JSON,我一无所知,但想从下“下”(或者其他用户的第二阵列的“假”值,真/假,从下“followed_by”第一阵列......无论哪种方式是好的)!

{"relationship":{"source":{"id":0000000000,"id_str":"0000000000","screen_name":"auth_user","following":false,"followed_by":false,"following_received":false,"following_requested":false,"notifications_enabled":false,"can_dm":false,"blocking":false,"blocked_by":false,"muting":false,"want_retweets":false,"all_replies":false,"marked_spam":false},"target":{"id":123456789,"id_str":"123456789","screen_name":"other_user","following":false,"followed_by":false,"following_received":false,"following_requested":false}}} 

我怎样才能让我的代码返回真/假的“以下”:假的一部分?

(或中,“followed_by”:第一阵列中假部分 - 每一个阵列是从用户的关系的“视点”)

回答

0

尼斯,解决了它发布之后立即。

尝试:

print json.loads(api.show_friendship(target_id=user_id))["relationship"]["target"]["followed_by"] 

您可以通过指定每个分支通过JSON阵列工作,你去通过它(我敢肯定,很多人都知道笑,但我从来没有使用JSON!)。 ..

0
print api.show_friendship(target_screen_name=screen_name)[1].following