"user":{"contributors_enabled":false,
created_at":"Wed Jul 21 00:30:00 +0000 2010","
default_profile":false,
"default_profile_image":false,"description":"",
"entities":{"description":{"urls":[]}},
"favourites_count":0,"follow_request_sent":false,
你可以像这样从user
得到id
-
例
records = {
"user":{
"contributors_enabled":false,
"created_at":"Wed Jul 21 00:30:00 +0000 2010",
"default_profile":false,
"default_profile_image":false,
"description":"",
"entities":{
"description":
{"urls":[]}
},
"favourites_count":0,
"follow_request_sent":false,
"has_extended_profile":false,
"id":168873000,
"id_str":"168873000",
"is_translation_enabled":false,
"is_translator":false,
"lang":null,
"listed_count":0,
"location":"",
"name":"elaine cristina lima",
"notifications":false,
"profile_background_color":"FF6699"
}
}
法典:
records['user']['id'] #168873000
这将从user
返回id
参考:
https://realpython.com/python-json/
编辑
通过从 .json 文件读取从user
获取id
的代码 -
def records_from(json_path):
'''Return the records read from .json file json_path
'''
with open(json_path, 'r') as json_file:
records = json.load(json_file)
return records
jsondata = records_from(filename)
print(jsondata['user']['id']) # prints 168873000