我在 python 中使用 bolt 驱动程序 (1.0.1)。如何将结果转换为 Json,以便我可以通过 flask 应用程序将其返回? 那就是我需要将数据类型“neo4j.v1.types.Record”转换为“json”。
我试过了
from flask import Flask
from neo4j.v1 import GraphDatabase, basic_auth
import json
driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j","neo4j"))
session = driver.session()
app = Flask(__name__)
@app.route('/hello/<prop>')
def hello_name(prop):
result = session.run("MATCH ...") #this works perfectly fine and the data is captured in result
session.close()
for record in result:
return json.loads(record)
这会引发错误:- TypeError:JSON 对象必须是 str,而不是“Record”
最佳答案
neo4j 驱动程序在生成器中给出结果。(记录类型)您不能执行 json.load,因为它不是 json 序列化字符串。
你可以做什么:
for record in result:
print result[0]
查看结果的格式并取你喜欢的元素。
进一步了解如何解析 neo4j 记录: http://neo4j.com/docs/api/python-driver/current/session.html
关于python - Neo4j Python bolt 驱动程序 : how to convert the result to Json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43775604/