[英]This given text is in json format.As i am new to python so tell me how can i get id from user only
"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,
You can get id
from user
like this -您可以像这样从user
那里获取id
-
Example例子
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"
}
}
Code:代码:
records['user']['id'] #168873000
This will return id
from user
这将从user
返回id
Reference:参考:
https://realpython.com/python-json/ https://realpython.com/python-json/
EDIT编辑
Code to get id
from user
by reading from .json file -通过读取 .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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.