从JSON Twitter响应(Tweepy和Python)中提取单个真/假值

从JSON Twitter响应(Tweepy和Python)中提取单个真/假值,python,arrays,json,twitter,tweepy,Python,Arrays,Json,Twitter,Tweepy,我正在尝试在一个应用程序中编写一点代码,检查用户是否在跟踪你。我只希望代码返回一个真/假值,我可以将其放入if循环中 代码是: user_id = '1234567890' print api.show_friendship(target_id=user_id) 它返回所有这些JSON,我对这些JSON一无所知,但我希望在“following”下为其他用户从第二个数组中获取“false”值(或者,在“following_by”下从第一个数组获取true/false值……,任何一种方式都可以):

我正在尝试在一个应用程序中编写一点代码,检查用户是否在跟踪你。我只希望代码返回一个真/假值,我可以将其放入if循环中

代码是:

user_id = '1234567890'
print api.show_friendship(target_id=user_id)
它返回所有这些JSON,我对这些JSON一无所知,但我希望在“following”下为其他用户从第二个数组中获取“false”值(或者,在“following_by”下从第一个数组获取true/false值……,任何一种方式都可以):

如何使代码返回“following”:false部分的true/false


(或者,第一个数组中的“后跟”:false部分-每个数组都来自用户对关系的“观点”)

Nice,发布后立即解决

尝试:

您可以在处理JSON数组时指定每个分支(我相信很多人都知道lol,但我从未使用过JSON!)

真的

{"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}}}
print json.loads(api.show_friendship(target_id=user_id))["relationship"]["target"]["followed_by"]
print api.show_friendship(target_screen_name=screen_name)[1].following