我正在运行此代码时:
city_dict_humidity = dict()
city_dict_temperature = dict()
def on_message(client, userdata, msg):
if (msg.payload == 'Q'):
client.disconnect()
topics = msg.topic.split('/')
if topics[2] == 'humidity':
if topics[1] in city_dict_humidity:
city_dict_humidity[topics[1]].append(msg.payload)
else:
city_dict_humidity[topics[1]] = [msg.payload]
elif topics[2] == 'temperature':
if topics[1] in city_dict_temperature:
city_dict_temperature[topics[1]].append(msg.payload)
else:
city_dict_temperature[topics[1]] = [msg.payload]
vypis()
uloz_json()
def uloz_json():
with open('data.json','w') as wrt:
json.dump(city_dict_humidity,wrt)
我收到错误:TyperError:类型'字节'的对象不是JSON可序列化的。 请问在哪里?我不能在那里有名单吗?