一生热爱回头太难 2021-01-27 16:33 采纳率: 50%
浏览 199
已采纳

Python怎么从json中提取数据id和text

[{
    "id": 4541,
    "iconCls": "icon-blank",
    "state": "closed",
    "text": "\u9042\u5e73\u53bf\u8fd0\u7ba1\u6240<a href=\"#\" style=\"font-size: 20px; position: absolute; right: 3px;\" onclick=\"setOrg(4541, '\u9042\u5e73\u53bf\u8fd0\u7ba1\u6240', event)\"><\/a>",
    "attributes": {
        "categoryID": 1004
    }
}, {
    "id": 4829,
    "iconCls": "icon-blank",
    "state": "closed",
    "text": "\u9a7b\u9a6c\u5e97\u5e02\u8fd0\u9686\u5b9e\u4e1a\u80a1\u4efd\u6709\u9650\u516c\u53f8<a href=\"#\" style=\"font-size: 20px; position: absolute; right: 3px;\" onclick=\"setOrg(4829, '\u9a7b\u9a6c\u5e97\u5e02\u8fd0\u9686\u5b9e\u4e1a\u80a1\u4efd\u6709\u9650\u516c\u53f8', event)\"><\/a>",
    "attributes": {
        "categoryID": 1005
    }
}]

  • 写回答

2条回答 默认 最新

  • Miku丨无形 2021-01-27 16:41
    关注
    import json
    
    s = '[{
        "id": 4541,
        "iconCls": "icon-blank",
        "state": "closed",
        "text": "\u9042\u5e73\u53bf\u8fd0\u7ba1\u6240<a href=\"#\" style=\"font-size: 20px; position: absolute; right: 3px;\" onclick=\"setOrg(4541, '\u9042\u5e73\u53bf\u8fd0\u7ba1\u6240', event)\"><\/a>",
        "attributes": {
            "categoryID": 1004
        }
    }, {
        "id": 4829,
        "iconCls": "icon-blank",
        "state": "closed",
        "text": "\u9a7b\u9a6c\u5e97\u5e02\u8fd0\u9686\u5b9e\u4e1a\u80a1\u4efd\u6709\u9650\u516c\u53f8<a href=\"#\" style=\"font-size: 20px; position: absolute; right: 3px;\" onclick=\"setOrg(4829, '\u9a7b\u9a6c\u5e97\u5e02\u8fd0\u9686\u5b9e\u4e1a\u80a1\u4efd\u6709\u9650\u516c\u53f8', event)\"><\/a>",
        "attributes": {
            "categoryID": 1005
        }
    }]'
    data = json.loads(s)
    data_id = [i['id'] for i in data]
    data_text = [i['text'] for i in data]
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制