Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python json转储将对象放入第\u到\u行json返回的对象中_Python_Json_Postgresql - Fatal编程技术网

python json转储将对象放入第\u到\u行json返回的对象中

python json转储将对象放入第\u到\u行json返回的对象中,python,json,postgresql,Python,Json,Postgresql,我正在用python运行一个Postgres查询,它返回一个JSON对象数组 db = SQLDB('postgres://postgres:*****@localhost:5433/postgres', migrate=False) q = ("SELECT row_to_json(t) FROM (SELECT * FROM fn_drivetime_eu_grid_" + request.get_vars.country + "_coord(" + request.get_

我正在用python运行一个Postgres查询,它返回一个JSON对象数组

    db = SQLDB('postgres://postgres:*****@localhost:5433/postgres', migrate=False)
    q = ("SELECT row_to_json(t) FROM (SELECT * FROM fn_drivetime_eu_grid_" + request.get_vars.country + "_coord(" + request.get_vars.x + ", " + request.get_vars.y + ", " + request.get_vars.sec + ")) t;")
    mySQL = db.executesql(q)
    return json.dumps(mySQL)
问题是这些对象位于对象内部。老兄

这不是什么大问题,但我想知道是否有更优雅的解决方案


如果转储整个结果集,就会发生这种情况。使用
t
表格:

create table t (a int, b text);
insert into t (a, b) values (1,'x'), (2,'y');
使用Psycopg2:

query = "select row_to_json(t) from t"
cursor.execute(query)
rs = cursor.fetchall()

# dump the whole result set
print json.dumps(rs)
print

# dump each column:
for r in rs:
    print json.dumps(r[0])
con.close()
输出:

[[{"a": 1, "b": "x"}], [{"a": 2, "b": "y"}]]

{"a": 1, "b": "x"}
{"a": 2, "b": "y"}

显示Python代码和查询输出。我扩展了代码示例。我们有没有可能看到原始JSON而不是它当前显示的任何工具?