Python 从json文件中提取用户ID
我有一个json文件,其中包含来自趋势标签的tweets数据,现在在创建我的子文件后,我只需要提取所有用户的用户名。 尝试使用以下代码会导致错误: 文件/Users/Adel/Documents/Tweepy/jsonextracting.py,第19行,在 my_dict['id']=项目。获取'id' AttributeError:“unicode”对象没有属性“get” python代码:Python 从json文件中提取用户ID,python,json,Python,Json,我有一个json文件,其中包含来自趋势标签的tweets数据,现在在创建我的子文件后,我只需要提取所有用户的用户名。 尝试使用以下代码会导致错误: 文件/Users/Adel/Documents/Tweepy/jsonextracting.py,第19行,在 my_dict['id']=项目。获取'id' AttributeError:“unicode”对象没有属性“get” python代码: import json input_file=open('/Users/Adel/Downloads
import json
input_file=open('/Users/Adel/Downloads/data/test.json', 'r')
output_file=open('/Users/Adel/Downloads/data/test2.json', 'w')
json_decode=json.load(input_file)
for item in json_decode:
my_dict={}
my_dict['id']=item.get('id')
print my_dict
back_json=json.dumps(my_dict, output_file)
output_file.write(back_json)
output_file.close()
非常感谢您的帮助。当您在字典上迭代时,您只需在键上迭代,请尝试
for item in json_decode.values():
它将迭代这些值