Python - 将列表转储到json中

时间:2017-04-13 17:19:58

标签: python json python-3.x dump serializable

我正在运行此代码时:

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可序列化的。 请问在哪里?我不能在那里有名单吗?

0 个答案:

没有答案