修复python烧瓶应用程序的JSON.PARSE语法错误
我正在尝试使用JSON.PARSE在烧瓶应用程序中使用一些JSON数据。但是,我会遇到以下错误。
uckulting语法:在位置3的JSON中意外的令牌m
我怀疑这可能与报价有关,但不确定。代码在下面。
python(app.y)
import pandas as pd
from flask import Flask, render_template
import json
test_data = [['mack', 10, 988], ['john', 15, 200], ['jane', 14, 590]]
test_df = pd.DataFrame(test_data, columns=['Name', 'Age', 'Score'])
json_df = test_df.set_index('Name').to_json(orient='index')
@app.route("/hello")
def index():
return render_template("index.html", json_df=json_df)
javaScript (在我的index.html文件中)
<script>
const json_df = JSON.parse('{{ json_df|tojson }}');
console.log(json_df);
</script>
,我希望能够与JavaScript中的数据一起工作,以:
const json_df = {mack:{Age:10,Score:988},john:{Age:15,Score:200},jane:{Age:14,Score:590}}
I'm trying to work with some JSON data into my JavaScript using JSON.parse in my Flask app. However, I'm getting the following error.
Uncaught SyntaxError: Unexpected token m in JSON at position 3
I'm suspecting it may be something to do with the quotes, but am not sure. Code is below.
Python (app.y)
import pandas as pd
from flask import Flask, render_template
import json
test_data = [['mack', 10, 988], ['john', 15, 200], ['jane', 14, 590]]
test_df = pd.DataFrame(test_data, columns=['Name', 'Age', 'Score'])
json_df = test_df.set_index('Name').to_json(orient='index')
@app.route("/hello")
def index():
return render_template("index.html", json_df=json_df)
JavaScript (within my index.html file)
<script>
const json_df = JSON.parse('{{ json_df|tojson }}');
console.log(json_df);
</script>
Basically, I want to be able to work with the data in JavaScript, such that:
const json_df = {mack:{Age:10,Score:988},john:{Age:15,Score:200},jane:{Age:14,Score:590}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论