要从字典中取出content的数组,可以使用下标操作符[]来获取字典中的值,然后使用键"content"来访问对应的数组。以下是使用Swift代码来实现的示例:

let dictionary: [String: Any] = [
    "code": 200,
    "cmd": 101,
    "content": [
        [
            "video_id": "4638",
            "nickname": "游客156011",
            "avatar": "https://lyt.longyou.gov.cn:30443/oss/btsj-lyt/avatar/8.png",
            "content": "ping",
            "send_time": "2023-09-13 14:16:59"
        ],
        // 其他内容
    ]
]

if let contentArray = dictionary["content"] as? [[String: Any]] {
    // 使用contentArray进行后续操作
    print(contentArray)
} else {
    print("无法获取content的数组")
}

在上面的示例中,首先将字典赋值给dictionary变量。然后使用下标操作符[]来获取键为"content"的值,并将其转换为[[String: Any]]类型的数组。如果转换成功,则可以使用contentArray变量进行后续操作,例如打印数组内容。如果无法获取content的数组,则会打印"无法获取content的数组"。

Swift 字典code 200 cmd 101 content video_id4638nickname游客156011avatarhttpslytlongyougovcn30443ossbtsj-lytavatar8pngcontentpingsend_time2023-09-13 141659video_id4638nickname游客250185avatarhttpslytlongyoug

原文地址: https://www.cveoy.top/t/topic/i7De 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录