Python で特定の JSON オブジェクトを生成するのに問題があります。
次の形式にする必要があります。
[
{"id":0 , "attributeName_1":"value" , "attributeName_2":"value" , .... },
{"id":1 , "attributeName_2":"value" , "attributeName_3":"value" , .... },
.
.
.
]
Python では、2 つのオブジェクトから ID、属性名、および値を取得しています。次のようなjsonを生成しようとしています:
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)
しかし、私はこの結果を得ましたが、これはまさに私が必要としているものではありません:
[
{"id":0} , {"attributeName_1":"value"} , {"attributeName_2":"value"} ,
{"id":1} , {"attributeName_2":"value"} , {"attributeName_3":"value"} , .... },
.
.
.
]