ich benötige ein leeres JSON Objekt in der Form [], damit ich Stückweise folgende Struktur aufbauen kann (Beispiel JSON)
Code: Alles auswählen
[{
"id": "581f484957d3f",
"title": "1",
"description": "1",
"sensoren": [{
"id": "581f486a559fd",
"title": "1a",
"number": "1",
"temp": "",
"humidity": "",
"time": ""
}],
"geraete": [{
"id": "581f487fde7c4",
"title": "jo",
"type": "Heizmatte",
"device": "234",
"number": "2",
"status": false,
"schaltung": [{
"id": "581f491c574d2",
"on": "asdasdas",
"off": "asdasdasddasdasdasdasd"
}, {
"id": "581f492ef1004",
"on": "123",
"off": "123"
}]
}]
}, {
"id": "581f486261a78",
"title": "2",
"description": "2",
"sensoren": [{
"id": "581f48718878c",
"title": "2a",
"number": "2",
"temp": "",
"humidity": "",
"time": ""
}],
"geraete": [{
"id": "581f48890ef20",
"title": "ghfhfghgf",
"type": "Heizmatte",
"device": "dasd",
"number": "1",
"status": false,
"schaltung": [{
"id": "581f4936a1968",
"on": "asdas",
"off": "dsasdasd"
}]
}]
}]
Hier mal ein prototyp:
Code: Alles auswählen
import json
import zmq
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://127.0.0.1:5000")
jsonV = "[]"
#json = json.loads("[]")
while True:
msg = socket.recv()
print msg
message = msg.split('/')
if message[0] == "t":
print message
print json.dumps(jsonV);
socket.send("ok")
elif message[0] == "i":
try:
jsonV = message[1]
print 'bestehende JSON-Konfiguration ueberschrieben:'
#print json.dumps(jsonV)
print jsonV
except IndexError:
print 'bestehende JSON-Konfiguration ausgegeben:'
print jsonV
#print json .dumps(jsonV)
#socket.send(json.dumps(jsonV))
socket.send(jsonV)
else:
socket.send('error')