简体   繁体   English

从 Microsoft Graph 中的特定点映射 API、Python

[英]Mapping from a specific point in Microsoft Graph API, Python

I've been beating my head against the wall for a couple of days now and can't quite come up with an answer.几天来,我一直在用头撞墙,无法完全找到答案。

Inside of the Microsoft Graph API, when you call for a specific type of email data it sends a JSON with a 'value' read at the top level.在 Microsoft Graph API 内部,当您调用特定类型的 email 数据时,它会发送 JSON 并在顶层读取“值”。


    {
        "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('938381cd-71f5-4a3d-a381-0a59a721948a')/messages",
        "value": [
            {
                "@odata.etag": "W/\"CQAAABYAAAD0YZL2mrEQQpwOvq9h/XWNAAACpJ2E\"",
                "bccRecipients": [],
                "body": {

I'm attempting to dump the JSON into a dict and go into the value key to be able to get to the data I actually need.我正在尝试将 JSON 转储到 dict 中,并将 go 转储到 value 键中,以便能够获取我实际需要的数据。


    print('\nGet user unread messages -> https://graph.microsoft.com/v1.0/me/messages?$filter=isRead ne true')
        user_MAIL = session.get(api_endpoint('me/messages?$filter=isRead ne true'))
     {len(user_MAIL.text)}\n')
        text = json.dumps(user_MAIL.json(), indent=4, sort_keys=True)

The issue I keep running into is I can't figure out how to access the 'value' part.我一直遇到的问题是我不知道如何访问“价值”部分。 In Javascript I know I could just do something like a.map, but I've attempted several things here and can't seem to find an answer.在 Javascript 中,我知道我可以做类似 a.map 的事情,但我在这里尝试了几件事,但似乎找不到答案。

All I need to do is be able to enter the data from the value, and be able to list the keys and values of everything within 'value'.我需要做的就是能够从值中输入数据,并能够列出“值”中所有内容的键和值。

I accidentally found the answer.我无意中找到了答案。

If you do a for loop like this:如果您执行这样的 for 循环:

for key in range(length):
        print (json_object['value'][key]['id'])
        print (28* ' ', "BREAK")  

You're able to access the top layer and grab exactly what you want, no matter how many loops you have.无论您有多少个循环,您都可以访问顶层并准确获取您想要的内容。

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

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