python / flask sql结果到JSON没有对象键?

时间:2016-11-11 13:59:43

标签: python json flask sqlalchemy

我对Python和Flask比较陌生,如果这是非常基本的话我很抱歉。我在我的方法中运行查询,如下所示:

    @app.route('/coreteams')
    def coreteams():
    db = FlaskApp.db_connect()
    coreteams = db.execute(text(
        "SELECT service_users.id AS user_id, core_teams.service_user, core_teams.staff_name , core_teams.role, staff_list.id AS staff_id, staff_list.status, core_teams.workbase" \
        " FROM core_teams" \
        " LEFT JOIN staff_list" \
        " ON staff_list.name = core_teams.staff_name" \
        " LEFT JOIN service_users" \
        " ON service_users.name = core_teams.service_user" \
        " WHERE staff_list.status <> 'Left'" \
        " AND staff_list.status <> 'Name Changed';"
    )).fetchall()

    return jsonify(core=coreteams)

我得到的结果与此类似:

{
  "core": [
    [
      3, 
      "Phillippa *********", 
      "Abbey *********", 
      "Activities", 
      2, 
      "Probation", 
      "The ************"
    ], 
    [
      60, 
      "Raymond ***********", 
      "Adam ************", 
      "Documentation", 
      8, 
      "Current", 
      "Old ****"
    ]
  ]
}

我会想象它应该是更多的事情:

{
  "core": [
    [
      "staff_id" : 3, 
      "staff_name" : "P H", 
      "user_name" : "A C", 
      "role" : "Activities", 
      "user_id" : 2, 
      "status" :"Probation", 
      "workbase" : "Location 1"
    ]
 ]
}

那么基本上返回JSON还包含数据库中的列名?这可能吗?

0 个答案:

没有答案