python取列表中字典的key和对应的value

有一个list如下

相关代码

[
  {
    "id": 1,
    "title": "test",
    "content": "hello world    ",
    "author": "akirayu",
    "create_time": 1490161295
  },
  {
    "id": 2,
    "title": "testforgood ",
    "content": "you are not hired for skills you are hired for your motivate    ",
    "author": "akirayu102",
    "create_time": 1490161714
  }
]

我想取key为"content" value为"you are not hired for skills you are hired for your motivate "

请问如何通过python获取呢?谢谢.

阅读 6.2k
2 个回答

list赋给变量data.使用data[1]['content']便可取得你要的内容。

import json

s="""
[
  {
    "id": 1,
    "title": "test",
    "content": "hello world    ",
    "author": "akirayu",
    "create_time": 1490161295
  },
  {
    "id": 2,
    "title": "testforgood ",
    "content": "you are not hired for skills you are hired for your motivate    ",
    "author": "akirayu102",
    "create_time": 1490161714
  }
]
"""

js = json.loads(s)

print(js[1]["content"])
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题