2015-02-17 111 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