简体   繁体   English

这个给定的文本是 json 格式。因为我是 python 的新手,所以告诉我如何只从用户那里获取 id

[英]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.

相关问题 我如何从给定记录中获取用户ID值 - How can i get the user id value from a given record 有人可以告诉我我做错了什么新到 Python - Can someone please tell me what am I doing wrong New to Python 尝试以 json 格式对我的数据进行分析。 到目前为止,我的代码下面我的问题是如何加入我的所有数据,请帮助我是 Python 新手 - trying do analysis to my data in json format. my code below so far my questions is how can I join all my data , pls help I am new to python 我如何从格式 json 获取此文本? - How can i get from format json this text? 如何让 mypy 告诉我我正在使用旧 Python 版本不支持的功能? - How can I make mypy tell me I am using features that are unsupported in older Python versions? 我正在尝试用Python语言创建一个函数。 谁能告诉我如何从中获得输出? - I am trying to create a function in Python language. Can anyone show me how to get an output from it? 我收到 TypeError: can only concatenate str (not "NoneType") to str while using tkinter,请告诉我如何解决这个问题 - I am getting TypeError: can only concatenate str (not "NoneType") to str while using tkinter, please tell me how can fix this 谁能告诉我为什么我在 flask 中收到“NameError: name 'validators' is not defined”? 因为我是 flask 的新手 - Can anyone tell me why i am getting “NameError: name 'validators' is not defined” in flask? As i am new to flask 如何使用自省功能让Python告诉我更多有关PIL ImagingCore对象的信息? - How can I use introspection to get Python to tell me more about PIL ImagingCore objects? 如何从头开始创建一个表,让我使用 python 获取每个用户的最后订单? - How can I create from scratch a table that allows me to get the last order of each user using python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM