使用python web服务将Sql查询结果提供给highchart

使用python web服务将Sql查询结果提供给highchart,python,sql-server,highcharts,Python,Sql Server,Highcharts,注意:下面的代码又大又难看,但我确信问题只存在于列表testlist @app.post('/salesvolume') def salesvolume(db): testlist = [] res = db.execute(""" SELECT CAST ((SUM(r.SalesVolume)/1000.0) AS decimal(6,1)) FROM RawData r INNER JOIN Product p ON r.ProductId

注意:下面的代码又大又难看,但我确信问题只存在于列表
testlist

@app.post('/salesvolume')
def salesvolume(db):

    testlist = []
    res = db.execute("""
    SELECT CAST ((SUM(r.SalesVolume)/1000.0) AS decimal(6,1))
    FROM RawData r
    INNER JOIN Product p
    ON r.ProductId = p.ProductId 
    INNER JOIN Calendar c
    ON r.DayId = c.DayId
    WHERE c.WeekCodeInYear BETWEEN 1 AND 12
    AND 
    c.YearId = 2014
    GROUP BY c.WeekCodeInYear """)

    for row in res:
         testlist.append (row[0])

ret = """{
    "chart": {
        "type": "column"
        },
    "colors": [
            "#00B7DE",
            "#00539E"
            ],
    "title": {
        "text": "SALES - VOLUME"
    },
    "xAxis": {
        "categories": ["W", "W", "W", "W", "W", "W", "W", "W", "W", "W", "W", "W"],
        "tickLength": 0
    },
    "yAxis": {
        "gridLineWidth": 0,
        "minorGridLineWidth": 0,
        "min": 0,
        "title": {
            "text": "K EURO"
        },
        "labels": {
            "enabled": false
        },
        "stackLabels": {
            "enabled": true,
            "style": {
                "fontWeight": "bold",
                "color": "gray"
            }

        }
    },
    "credits": {
        "enabled": false
    },

    "legend": {
        "align": "right",
        "x": -30,
        "verticalAlign": "top",
        "y": 25,
        "floating": true,
        "backgroundColor": "white",
        "borderColor": "#CCC",
        "borderWidth": 1,
        "shadow": true
    },
    "plotOptions": {
        "column": {
            "stacking": "normal",
            "dataLabels": {
                "enabled": true,
                "color": "white",
                "style": {
                    "textShadow": "0 0 3px black"
                }
            }
        }
    },
    "series": [{
        "name": "EST",
        "data": testlist
    }, {
        "name": "VOD",
        "data": testlist
    }]
    }"""  
return json.loads(ret) 

app.run(server='paste', host='localhost', port=8080, debug=True, reloader=True)
在上面的代码中,我需要将sql查询的结果作为highchart的数据输入。但是当我运行代码时,我得到一个错误
ValueError:没有JSON对象可以被解码

Sql查询的结果没有问题,因为我可以成功地打印它。它是一个具有12个十进制值的列。不知道该怎么做。

您说过SQL结果很好,但是一旦对结果运行循环,testlist的内容会怎么样?什么是抛出错误?python(我对Python一无所知)或者其他什么?您说过SQL结果很好,但是一旦对结果运行循环,testlist的内容会怎么样?什么是抛出错误?python(我对Python一无所知)还是别的什么?