this is my code:
import json
from pprint import pprint
with open('unAnsQuestions.json') as data_file:
data = json.load(data_file)
print(len(data))
json_len = len(data)
json_len+=1
with open('unAnsQuestions.json', "a") as json_file:
json.dump({'id':json_len,'fileName':'yogesh'},json_file,indent=2)
#json_file.write("{}\n".format(json.dumps(json_len)))
[{
"id":1,
"text":"hey?",
"answer":"hi"
},
{
"id":2,
"text":"bye.?",
"answer":"see you"
}]
ウェルフォーマットパイソンを取得idと 別のファイル名です。次はjson構造です。 データを追加します。 - jsonファイルに値を追加します。 - 私はいくつかのデータを含むQuestion.jsonを持っています:
しかし、私はこの出力を得るいくつかの値を追加するつもりです これは適切なformat.Iでこの値をブラケット '[]'。アペンドJSON値ではなく、これはJSONのfile.firstに2つの値を追加私のコードです[{ "id":1, "text":"hey?", "answer":"hi" }, { "id":2, "text":"bye.?", "answer":"see you" }] { "id": 3, "text":"bye.?", "answer":"see you" } so, the "]" is not well formatted. I tried many times but I didn't get output.can you please tell me the exact way?
コードを投稿してください –