我试图在json文件中写入一个特定的字符串。我的代码如下:from pymongo import MongoClient
client = MongoClient()
client = MongoClient('localhost', 27017)
db = client['my_db_values']
collection = db['db_values']
json_file = {"User": "2145", "Item": {"123456": {}}}
temp_json1 = {"timestamp": "2123532158", "process1_value": 0.4, "state": {"B": 0.1, "F": 0.2, "E": 0.3}}
temp_json2 = {"timestamp": "2323532158", "process2_value": 0.2, "P": 0.8}
json_file ["Item"][str(123456)]["process1"].append(temp_json1)
json_file ["Item"][str(123456)]["process2"].append(temp_json2)
实际上,我已经创建了json文件“json_file”,我想为process1和process2添加子json,这将是“Item”字段的子类别。我的代码无法按我的要求工作,我收到以下错误:json_file ["Item"][str(213546879213)]["process1"].append(temp_json1)
TypeError: 'set' object has no attribute 'getitem'
我的json希望看起来像:
^{pr2}$