Me da este error al intentar iterar un json :
counter.append(dato['monitorCounter'])
TypeError: string indices must be integers, not str
Esta sería la parte de código donde ocurre el error:
y = json.dumps(result_set)
counter=[]
for dato in y:
counter.append(dato['monitorCounter'])
print counter
El json es este, que es la variable y, que esta transformando en json result_set, basicamente con ese for y la lista counter, quiero coger los datos 'monitorCounter' y mostrarlos.
[[["cn=Monitor", {}]], [["cn=Backends,cn=Monitor", {}]], [["cn=Backend 0,cn=Backends,cn=Monitor", {}]], [["cn=Backend 1,cn=Backends,cn=Monitor", {}]], [["cn=Backend 2,cn=Backends,cn=Monitor", {}]], [["cn=Backend 3,cn=Backends,cn=Monitor", {}]], [["cn=Backend 4,cn=Backends,cn=Monitor", {}]], [["cn=Backend 5,cn=Backends,cn=Monitor", {}]], [["cn=Connections,cn=Monitor", {}]], [["cn=Connection 1016,cn=Connections,cn=Monitor", {"monitorConnectionRead": ["2"], "monitorConnectionGet": ["2"], "monitorConnectionOpsReceived": ["2"], "monitorConnectionOpsCompleted": ["1"], "monitorConnectionNumber": ["1016"], "monitorConnectionWrite": ["0"], "monitorConnectionOpsExecuting": ["1"], "monitorConnectionOpsPending": ["0"]}]], [["cn=Max File Descriptors,cn=Connections,cn=Monitor", {"monitorCounter": ["1024"]}]], [["cn=Total,cn=Connections,cn=Monitor", {"monitorCounter": ["1017"]}]], [["cn=Current,cn=Connections,cn=Monitor", {"monitorCounter": ["1"]}]], [["cn=Databases,cn=Monitor", {}]], [["cn=Frontend,cn=Databases,cn=Monitor", {}]], [["cn=Database 0,cn=Databases,cn=Monitor", {}]], [["cn=Database 1,cn=Databases,cn=Monitor", {}]], [["cn=Database 2,cn=Databases,cn=Monitor", {"olmBDBEntryCache": ["0"], "olmBDBIDLCache": ["0"], "olmBDBDNCache": ["0"]}]], [["cn=Listeners,cn=Monitor", {}]], [["cn=Listener 0,cn=Listeners,cn=Monitor", {}]], [["cn=Listener 1,cn=Listeners,cn=Monitor", {}]], [["cn=Listener 2,cn=Listeners,cn=Monitor", {}]], [["cn=Log,cn=Monitor", {}]], [["cn=Operations,cn=Monitor", {"monitorOpInitiated": ["50"], "monitorOpCompleted": ["49"]}]], [["cn=Bind,cn=Operations,cn=Monitor", {"monitorOpInitiated": ["17"], "monitorOpCompleted": ["17"]}]], [["cn=Unbind,cn=Operations,cn=Monitor", {"monitorOpInitiated": ["16"], "monitorOpCompleted": ["16"]}]], [["cn=Search,cn=Operations,cn=Monitor", {"monitorOpInitiated": ["17"], "monitorOpCompleted": ["16"]}]], [["cn=Compare,cn=Operations,cn=Monitor", {"monitorOpInitiated": ["0"], "monitorOpCompleted": ["0"]}]], [["cn=Modify,cn=Operations,cn=Monitor", {"monitorOpInitiated": ["0"], "monitorOpCompleted": ["0"]}]], [["cn=Modrdn,cn=Operations,cn=Monitor", {"monitorOpInitiated": ["0"], "monitorOpCompleted": ["0"]}]], [["cn=Add,cn=Operations,cn=Monitor", {"monitorOpInitiated": ["0"], "monitorOpCompleted": ["0"]}]], [["cn=Delete,cn=Operations,cn=Monitor", {"monitorOpInitiated": ["0"], "monitorOpCompleted": ["0"]}]], [["cn=Abandon,cn=Operations,cn=Monitor", {"monitorOpInitiated": ["0"], "monitorOpCompleted": ["0"]}]], [["cn=Extended,cn=Operations,cn=Monitor", {"monitorOpInitiated": ["0"], "monitorOpCompleted": ["0"]}]], [["cn=Overlays,cn=Monitor", {}]], [["cn=Overlay 0,cn=Overlays,cn=Monitor", {}]], [["cn=SASL,cn=Monitor", {}]], [["cn=Statistics,cn=Monitor", {}]], [["cn=Bytes,cn=Statistics,cn=Monitor", {"monitorCounter": ["55414"]}]], [["cn=PDU,cn=Statistics,cn=Monitor", {"monitorCounter": ["928"]}]], [["cn=Entries,cn=Statistics,cn=Monitor", {"monitorCounter": ["896"]}]], [["cn=Referrals,cn=Statistics,cn=Monitor", {"monitorCounter": ["0"]}]], [["cn=Threads,cn=Monitor", {}]], [["cn=Max,cn=Threads,cn=Monitor", {}]], [["cn=Max Pending,cn=Threads,cn=Monitor", {}]], [["cn=Open,cn=Threads,cn=Monitor", {}]], [["cn=Starting,cn=Threads,cn=Monitor", {}]], [["cn=Active,cn=Threads,cn=Monitor", {}]], [["cn=Pending,cn=Threads,cn=Monitor", {}]], [["cn=Backload,cn=Threads,cn=Monitor", {}]], [["cn=State,cn=Threads,cn=Monitor", {}]], [["cn=Runqueue,cn=Threads,cn=Monitor", {}]], [["cn=Tasklist,cn=Threads,cn=Monitor", {}]], [["cn=Time,cn=Monitor", {}]], [["cn=Start,cn=Time,cn=Monitor", {}]], [["cn=Current,cn=Time,cn=Monitor", {}]], [["cn=Uptime,cn=Time,cn=Monitor", {}]], [["cn=TLS,cn=Monitor", {}]], [["cn=Waiters,cn=Monitor", {}]], [["cn=Read,cn=Waiters,cn=Monitor", {"monitorCounter": ["1"]}]], [["cn=Write,cn=Waiters,cn=Monitor", {"monitorCounter": ["0"]}]]]
Como podría iterar ese json para coger solo los valores monitorCounter??
por ejemplo de esto :
[["cn=Write,cn=Waiters,cn=Monitor", {"monitorCounter": ["0"]}]]
Coger solo el 0