Ich habe Schwierigkeiten, ein bestimmtes JSON-Objekt in Python zu generieren.JSON - Generieren eines JSON in einer Schleife in Python
Ich brauche es in diesem Format zu sein:
[
{"id":0 , "attributeName_1":"value" , "attributeName_2":"value" , .... },
{"id":1 , "attributeName_2":"value" , "attributeName_3":"value" , .... },
.
.
.
]
In Python, im die ids, attribute und Werte von 2 Objekten zu bekommen. Im Versuch, die json wie folgt zu generieren:
data=[]
for feature in features_selected:
data.append({"id":feature.pk})
for attribute in attributes_selected:
if attribute.feature == feature:
data.append({attribute.attribute.name : attribute.value})
jsonData=json.dumps(data)
aber ich habe dieses Ergebnis, das nicht genau das, was ich brauche:
[
{"id":0} , {"attributeName_1":"value"} , {"attributeName_2":"value"} ,
{"id":1} , {"attributeName_2":"value"} , {"attributeName_3":"value"} , .... },
.
.
.
]