在Python中解析json输出

时间:2016-07-27 22:02:58

标签: python json python-2.7 python-3.x

{
        "set" : "rs01",
        "date" : ISODate("2016-07-27T21:05:04Z"),
        "myState" : 1,
        "members" : [
                {
                        "_id" : 0,
                        "name" : "myserver1:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 608144,
                        "optime" : Timestamp(1469650746, 1),
                        "optimeDate" : ISODate("2016-07-27T20:19:06Z"),
                        "electionTime" : Timestamp(1469653499, 1),
                        "electionDate" : ISODate("2016-07-27T21:04:59Z"),
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "myserver3.uu.server.com:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 11,
                        "optime" : Timestamp(1469650746, 1),
                        "optimeDate" : ISODate("2016-07-27T20:19:06Z"),
                        "lastHeartbeat" : ISODate("2016-07-27T21:05:03Z"),
                        "lastHeartbeatRecv" : ISODate("2016-07-27T21:05:03Z"),
                        "pingMs" : 0,
                        "lastHeartbeatMessage" : "syncing to: myserver1:27017",
                        "syncingTo" : "myserver1:27017"
                },
                {
                        "_id" : 2,
                        "name" : "myserver2.uu.server.com:27017",
                        "health" : 0,
                        "state" : 8,
                        "stateStr" : "(not reachable/healthy)",
                        "uptime" : 0,
                        "lastHeartbeat" : ISODate("2016-07-27T21:05:03Z"),
                        "lastHeartbeatRecv" : ISODate("2016-07-27T21:03:13Z"),
                        "pingMs" : 0
                }
        ],
        "ok" : 1
}

问题:

1)如何在python中解析这个json输出?

2)我想从输出中提取“健康”:1和“状态”:1。

0 个答案:

没有答案