builtins.TypeError TypeError:{2,5,23}不是JSON可序列化的

时间:2016-08-13 03:24:34

标签: python json serialization flask

这是我的代码 我在JSON中收到b.start_time无序列化错误。

def rooms():
    rooms = Room.query.all()       
    formatted_rooms = []
    for r in rooms:
        book = Booking.query.filter_by(room_id=r.id).all()
        formatted_rooms.append( {           
                'name' : r.name,
                'floor': r.floor, 'location': r.location, 
                'city' : r.city, 'capacity' : r.capacity,
                'credits' : r.credits, 'amenities' : r.amenities ,
                'room_id' : r.id,
                 'booking_details': { (b.start_time) 
                                     for b in book }
                                } )
    return json.dumps(formatted_rooms) , 200, {'Content-Type':'application/json'}

1 个答案:

答案 0 :(得分:0)

set不是JSON数据类型

更改此

'booking_details': { (b.start_time) for b in book }

到列表

'booking_details': [ (b.start_time) for b in book ]