如何在python中遍历复杂的json

2024-05-16 22:26:42 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在python中遍历这个json?我想访问标记,并在此基础上在文本中应用html格式标记。我想根据标记中提供的起点和终点在文本中添加标记

  {
    "content": [{
            "markups": [],
            "contentType": "MEDIA",
            "text": "You will be pleasantly surprised to see snow-capped mountains surrounding you in all directions!",
            "media": {
                "path": "https://cdn-images-1.medium.com/1*wwvQhdsEA_X4E5GG8JYSsQ.jpeg",
                "mediaType": "IMAGE",
                "height": 2389,
                "width": 5999
            }
        },
        {
            "markups": [],
            "contentType": "TITLE",
            "text": "Uncharted territories: Parvati Valley, Kalga, Kheerganga Trek"
        },
        {
            "markups": [{
                "type": "ITALICS",
                "start": 134,
                "end": 145
            }],
            "contentType": "BODY",
            "text": "If you have never wandered in the woods"
        }
    ]
}

Tags: textin标记文本youjsonhtml格式