简体   繁体   English

Twitter API Search App,返回某些json结果

[英]Twitter API Search App, return certain json results

import json
dict1 = {}
dict2 = {}
def js_r(tweets):
   with open(tweets) as js_r:
       # return(json.load(f_in))

       return(json.loads(json.dumps([])))
       [{}, {}]
       return json.loads(json.loads(get_info))
       return(json.load(f_in))
       result = json.loads(output)
       print(result)
       print(result['contributors'])
if __name__ == "__main__":

    my_data = js_r('tweets.json')
    print(my_data)

How do I access and print only user from the json file? 如何从json文件访问和仅打印用户?

just use 只是使用

with open('tweets.json') as f:
    result = json.load(f)
    print(result)
    print(result['contributors'])

In your code you are using with open(tweets) as js_r: where js_r is also a name of your method. 在您的代码中,您将with open(tweets) as js_r:其中js_r也是您的方法的名称。 use different variable name for that. 为此使用不同的变量名。 if you don't want to make method you can directly use my answer. 如果您不想制作方法,可以直接使用我的答案。

And

json.loads() is for string input, use json.load() json.loads()用于字符串输入,请使用json.load()

you can try this 你可以试试这个

result = []
for line in open('tweets.json', 'r'):
    result.append(json.loads(line))
print(result)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM