Modo più semplice per creare il json così da debuggarlo meglio

Dalla riga 90 alla 112, metodo più standard per creare il json (il problema "TypeError: string indices must be integers" sulla serialization di Django c'è ugualmente, ma così il codice è più pulito)
This commit is contained in:
2022-10-04 11:44:40 +02:00
parent 69a78d1bf4
commit 3a26a88114

View File

@@ -88,30 +88,18 @@ print("lista prezzi:",len(prezzo)) #sono stringhe ovvero ci sono anche prezzi co
#Crea file json formattato per jawanndenn con la lista dei nomi dei prodotti #Crea file json formattato per jawanndenn con la lista dei nomi dei prodotti
#scrive le prime righe del json (uguali ogni volta)
with open('jwndn.json', 'w') as jw:
jw.write("{\n")
jw.write(' "lifetime": "month",\n')
jw.write(' "equal_width": true,\n')
jw.write(' "title":')
jw.write('"')
jw.write(nrist)
jw.write('",')
jw.write("\n")
jw.write(' "options": \n')
#inserisce i nomi dei prodotti dalla lista data = {"lifetime": "month", "equal_width": "true", "title": nrist, "options": nome}
def writeListJSONFile(filepathname, lista):
with open('./jwndn.json', 'a+') as f:
json.dump(nome, f)
writeListJSONFile('./jwndn.json', nome) print(json.dumps(data))
#conclude il json con l ultima parentesi graffa def writeListJSONFile(filepathname):
with open('jwndn.json', 'a+') as jw: with open('jwndn.json', 'w') as f:
jw.write("\n}\n") f.write(json.dumps(data))
writeListJSONFile('./jwndn.json')
# #
#storare in "tel" il numero di telefono dle ristorante #storare in "tel" il numero di telefono dle ristorante