7
私はPythonで特定のJSONオブジェクトを生成するのにいくつかの問題があります。JSON - Pythonのループでjsonを生成
私はそれがこの形式である必要があります:Pythonで
[
{"id":0 , "attributeName_1":"value" , "attributeName_2":"value" , .... },
{"id":1 , "attributeName_2":"value" , "attributeName_3":"value" , .... },
.
.
.
]
、イムは、2つのオブジェクトから、IDS、attributeNamesと値を取得します。イムは、このような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"} , .... },
.
.
.
]