简体   繁体   English

如何使用 Python 从字典中提取嵌套的字母数字值

[英]How do I extract a nested alphanumeric value from a dictionary using Python

I have a dictionary as follows:我有一本字典如下:

{
    'statusCode': 200,
    'body': '{"message": "data product request creation successful", "id": "a84f04f2539f11eca7ba0e2e68e2041f"}'
}

I want to extract the "id" inside the "body" key.我想提取“body”键中的“id”。

You'll want to have a look at the json module .你会想看看json 模块 Here is a basic example of how to do what you want:这是一个如何做你想做的事情的基本例子:

import json

d = {'statusCode': 200, 'body': '{"message": "data product request creation successful", "id": "a84f04f2539f11eca7ba0e2e68e2041f"}'}
body = json.loads(d['body'])

print(body['id'])
# a84f04f2539f11eca7ba0e2e68e2041f

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

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